package com.bbx.taxi.client.Activity.Order;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Editable;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMap.OnMapStatusChangeListener;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.InfoWindow;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.baidu.mapapi.utils.DistanceUtil;
import com.bbx.androidapi.util.DensityUtil;
import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.gclient.GMsg;
import com.bbx.api.sdk.SDK;
import com.bbx.api.sdk.model.passanger.Return.CarType.CarType;
import com.bbx.api.sdk.model.passanger.Return.Jmsg.Msgs;
import com.bbx.api.sdk.model.passanger.Return.LastPriceInfo;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.MyOrderList;
import com.bbx.api.sdk.model.passanger.Return.NearByDriver;
import com.bbx.api.sdk.model.passanger.Return.NearByDriver.DriverDetails;
import com.bbx.api.sdk.model.passanger.Return.Position;
import com.bbx.api.sdk.model.passanger.Return.PushStatus;
import com.bbx.api.sdk.model.passanger.Return.ShareDetail;
import com.bbx.api.sdk.model.passanger.Return.UsableSale;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.util.LogUtils;
import com.bbx.taxi.client.Activity.Base.BaseMapBBXActivity;
import com.bbx.taxi.client.Activity.Main.MainActivity;
import com.bbx.taxi.client.Activity.Menu.MyOrderActivity;
import com.bbx.taxi.client.Adapter.Chat.ChatMessageListAdapter;
import com.bbx.taxi.client.Adapter.Chat.ExpressionImageAdapter;
import com.bbx.taxi.client.Adapter.Chat.MyFacePagerAdapter;
import com.bbx.taxi.client.Adapter.Page.MyPagerAdapter;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.ChatMessage;
import com.bbx.taxi.client.Bean.Expression;
import com.bbx.taxi.client.Bean.Extra.MainMsg;
import com.bbx.taxi.client.Bean.Extra.OrderMsg;
import com.bbx.taxi.client.Bean.Message.MyMesssage;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.DB.JmsgDB;
import com.bbx.taxi.client.DB.LineDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderingDB;
import com.bbx.taxi.client.DB.Util.DBcolumns;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.MyApplication.OnLocationResultListener;
import com.bbx.taxi.client.R;
import com.bbx.taxi.client.Task.MyOrderTask;
import com.bbx.taxi.client.Task.MyOrderingTask;
import com.bbx.taxi.client.Util.CouponUtils;
import com.bbx.taxi.client.Util.DateFormat;
import com.bbx.taxi.client.Util.FastBlur.ScreenUtils;
import com.bbx.taxi.client.Util.FormatUtil;
import com.bbx.taxi.client.Util.IsDataFail;
import com.bbx.taxi.client.Util.IsSnQiangDan;
import com.bbx.taxi.client.Util.MeasureViewUtils;
import com.bbx.taxi.client.Util.RequestUtils;
import com.bbx.taxi.client.Util.Tel;
import com.bbx.taxi.client.Util.VersionUtils;
import com.bbx.taxi.client.Util.ViewBitmap;
import com.bbx.taxi.client.Util.ZoomUtils;
import com.bbx.taxi.client.widget.Chat.DropdownListView;
import com.bbx.taxi.client.widget.Chat.DropdownListView.OnRefreshListenerHeader;
import com.bbx.taxi.client.widget.CircleProgressView;
import com.bbx.taxi.client.widget.Dailog.MessageDialog;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog;
import com.bbx.taxi.client.widget.MyViewPager;
import com.bbx.taxi.client.widget.SlidingDrawer.MultiDirectionSlidingDrawer;
import com.bbx.taxi.client.widget.SlidingDrawer.MultiDirectionSlidingDrawer.OnDrawerCloseListener;
import com.bbx.taxi.client.widget.SlidingDrawer.MultiDirectionSlidingDrawer.OnDrawerOpenListener;
import com.bbx.taxi.client.widget.XCArcMenu.XCArcMenuView;
import com.bbx.taxi.client.widget.XCArcMenu.XCArcMenuView.OnMenuItemClickListener;
import com.bbx.taxi.client.widget.XCArcMenu.XCArcMenuView.OnSwitchStateListener;
import com.bbx.taxi.client.widget.pop.DatePicker2;
import com.bbx.taxi.client.widget.pop.SharePopView;
import com.bbx.taxi.client.widget.pop.SharePopView.OnShareDetaiFinish;
import com.yanxuwen.pickerview.CustomPicker;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 等待派车跟开始服务界面
 */
public class StartServiceActivity extends BaseMapBBXActivity implements
		OnClickListener, OnRefreshListenerHeader, OnShareDetaiFinish ,OnLocationResultListener,SensorEventListener{
	private final int ONLINE_CHAT = 1000;
	private String MSG_CONTENT = "msg_content";
	private String MSG_USER = "msg_user";
	private int I_ID = 0;// 我的ID
	private int YOU_ID = 1;// 司机的ID
	/** 订单详情的V */
	@Bind(R.id.viewpager)
	MyViewPager mViewPager;
	@Bind(R.id.input_sms)
	EditText input_sms;
	@Bind(R.id.send_sms)
	TextView send_sms;
	@Bind(R.id.drawer)
	MultiDirectionSlidingDrawer drawer;
	@Bind(R.id.handle_text)
	TextView handle_text;
	@Bind(R.id.btn_change_order)
	Button btn_change_order;// 修改订单
	@Bind(R.id.btn_order_detail)
	Button btn_order_detail;// 订单详情
	@Bind(R.id.btn_cancel_order)
	Button btn_cancel_order;// 取消订单
	@Bind(R.id.open_deawer)
	LinearLayout open_deawer;
	@Bind(R.id.image_add)
	ImageView image_add;
	@Bind(R.id.image_face)
	ImageView image_face;
	@Bind(R.id.layout_top)
	FrameLayout layout_top;
	@Bind(R.id.layout_startservice)
	RelativeLayout layout_startservice;
	@Bind(R.id.layout_bottom)
	RelativeLayout layout_bottom;
	@Bind(R.id.chat_face_container)
	LinearLayout chat_face_container;
	@Bind(R.id.chat_add_container)
	LinearLayout chat_add_container;
	/** QQ表情ViewPage的点 */
	@Bind(R.id.dots_face)
	LinearLayout dots_face;
	/** 订单的详情ViewPage的点 */
	@Bind(R.id.dots_top)
	LinearLayout dots_top;
	@Bind(R.id.face_viewpager)
	ViewPager face_viewpager;
	@Bind(R.id.message_chat_listview)
	DropdownListView mListView;
	@Bind(R.id.bmapView)
	MapView mMapView;
	@Bind(R.id.include_service_wait)
	LinearLayout include_service_wait;
	@Bind(R.id.iv_locate)
	ImageView iv_locate;
	@Bind(R.id.tv_price)
	TextView tv_price;
	@Bind(R.id.tv_total_price)
	TextView tv_total_price;
	@Bind(R.id.price_text)
	TextView price_text;
	@Bind(R.id.tv_estimat_time)
	TextView tv_estimat_time;
	@Bind(R.id.layout_thanks_fee)
	LinearLayout layout_thanks_fee;
	@Bind(R.id.tv_thanks_fee)
	TextView tv_thanks_fee;
	@Bind(R.id.tv_thanks_fee_text)
	TextView tv_thanks_fee_text;
	@Bind(R.id.iv_ad_exit)
	ImageView iv_ad_exit;
	@Bind(R.id.layout_ad)
	RelativeLayout layout_ad;
	@Bind(R.id.layout_price)
	LinearLayout layout_price;
	private TextView tv_notificati_car;
	private CircleProgressView mCircleProgressView;
	private BaiduMap mBaiduMap;
	private LayoutInflater inflater;
	/** 客服电话 */
	private ImageButton ib_kftel;
	/** 司机电话 */
	private ImageButton ib_sjtel;
	/** 订单集合 */
	private ArrayList<MyOrderList> list_order = new ArrayList<MyOrderList>();
	/** 订单消息集合,String订单Id,ArrayList<Map<String, String>>消息集合 */
	private Map<String, ArrayList<Map<String, String>>> map_jsmg = new HashMap<String, ArrayList<Map<String, String>>>();
	/** 订单详情页面集合 */
	private ArrayList<View> list_view = new ArrayList<View>();
	/** 根据订单order_id存储顺序id */
	private Map<String, Integer> map_id = new HashMap<String, Integer>();
	/** 订单详情页面的id */
	private int viewId = 0;
	/** 弧形菜单 */
	private XCArcMenuView mXCArcMenuView;
	/** 弧形菜单，添加订单 */
	private ImageView btn_tjdd;
	/** 弧形菜单父类 */
	private RelativeLayout parent_arcmenu;
	public static List<Expression> expressionList = new ArrayList<Expression>();
	private MyFacePagerAdapter mMyFacePagerAdapter;
	private ArrayList<GridView> grids;
	private int columns = 6, rows = 3, pageExpressionCount = 3 * 6 - 1;
	// --消息列表--//
	private ChatMessageListAdapter chatMessageListAdapter;
	private List<ChatMessage> l_msg = new ArrayList<ChatMessage>();
	private InitTask mInitTask;
	private int type_activity;
	private MyOrderingDB db_myordering;// 我的进行中的订单数据库
	private MyOrderDB db_myorder;// 我的进行中的订单数据库
	private JmsgDB db_jmsg;
	private Intent mIntent;

	int pressed = 0;
	public static final int MSG_LOCATION = 0;
	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case MSG_LOCATION:
				if (mBaiduMap != null && msg != null && msg.obj != null) {
					boolean isenabled = (Boolean) msg.obj;
					if (isSnQiangdan()) {
						isenabled = false;
					}
					if (mBaiduMap != null) {
						try {
							try{
								double latitude = MyApplication.getInstance().mLocation
										.getLatitude();
								double longitude = MyApplication.getInstance().mLocation
										.getLongitude();
								mBaiduMap.setMyLocationEnabled(isenabled);
								MyLocationData locData = new MyLocationData.Builder()
								.accuracy(0)
								// 此处设置开发者获取到的方向信息，顺时针0-360
//								.direction(direction)
								.direction(210)
								.latitude(latitude)
								.longitude(longitude).build();
						        mBaiduMap.setMyLocationData(locData);
						        if( mBaiduMap.getLocationConfigeration().customMarker==null){
						        	mBaiduMap
									.setMyLocationConfigeration(new MyLocationConfiguration(
											LocationMode.NORMAL, true,
											BitmapDescriptorFactory
													.fromResource(R.drawable.icon_mapid2)));
						        }
								}catch(Exception e){}
						} catch (Exception e) {
						}
					}

				}

				break;
			default:
				break;
			}
		};
	};

	public void removeHandler() {
		mHandler.removeCallbacks(position_run);
		mHandler.removeCallbacks(position_near);
		mHandler.removeCallbacks(position_time);
		// position_run=null;
		// position_run=new MyPosition_Run();
		// position_near=null;
		// position_near=new MyPositionNearByDriver();
		// position_time=null;
		// position_time=new MyPosition_Time();
	}

	public void onLocationEnabled(boolean isenabled) {
		Message msg = new Message();
		msg.obj = (Boolean) isenabled;
		msg.what = MSG_LOCATION;
		mHandler.sendMessageDelayed(msg, 100);
	}
	public void onLocationEnabled() {
		boolean isenabled=true;
		try{
		int status = list_order.get(viewId).getOrder_status();
		if(status == Value.ORDER_STATUS_ONCAR || status == Value.ORDER_STATUS_OFFCAR){
			isenabled=false;
		}
		}catch(Exception e){}
		Message msg = new Message();
		msg.obj = (Boolean) isenabled;
		msg.what = MSG_LOCATION;
		mHandler.sendMessageDelayed(msg, 100);
	}
	private MyPosition_Run position_run;
	private MyPositionNearByDriver position_near;
	private MyPosition_Time position_time;
	private MyPosition_jiFei position_jifei;
	MyAlertDailog dialog;
	// 初始化全局 bitmap 信息，不用时及时 recycle
	BitmapDescriptor bdSn = BitmapDescriptorFactory
			.fromResource(R.drawable.icon_map_start);
	BitmapDescriptor bdnear = BitmapDescriptorFactory
			.fromResource(R.drawable.icon_carx);
	BitmapDescriptor bdA = BitmapDescriptorFactory
			.fromResource(R.drawable.icon_addcar);
	BitmapDescriptor bd_start = BitmapDescriptorFactory
			.fromResource(R.drawable.icon_start);
	BitmapDescriptor bd_end = BitmapDescriptorFactory
			.fromResource(R.drawable.icon_finish);
	/** 附近的司机覆盖物 */
	private List<Marker> list_near_marker = new ArrayList<Marker>();
	/** 市内覆盖物 */
	private Marker mMarkerSn;
	/** 司机覆盖物 */
	private Marker mMarkerA;
	/** 起始点覆盖物 */
	private Marker mMarker_start;
	/** 终点覆盖物 */
	private Marker mMarker_end;
	/** 等待派车的父布局 */
	private LinearLayout layout_wait;
	/** 服务站的父布局 */
	private LinearLayout layout_service;
	/** 是否启动打开服务中的等待界面 */
	private boolean isOpenServiceWait = false;
	public List<String> sn_position_list = new ArrayList<String>();
	private LineDB db_line;// 线路数据库
	/** 判断是否可点击 */
	public boolean isClick = true;
//	public InfoWindow mInfoWindow;
	public InfoWindow mInfoWindowSN;
	private Resources res;
	/** 估计时间20分钟 */
	private int estimat_time = 20;
	int down_y = 0;
	LayoutInflater mInflater;
	DisplayMetrics dm;
	int mapwidth_center = 0;
	int mapBoundsWidth=0;
	int mapheight_center = 0;
	int mapBoundsHeight=0;
	//传感器
	private  SensorManager mSensorManager;
    private  Sensor mAccelerometer;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
		setContentView(R.layout.startservice);
		super.onCreate(savedInstanceState);
		mApplication.setOnLocationResultListener(this);
		/**实例化传感器*/
		mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
	    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
	}

	String extra_order_id;

	@Override
	protected void initView() {
		// 获取活动开关
		SharePopView mSharePopView = new SharePopView(context, null);
		mSharePopView.setOnShareDetaiFinish(this);
		mSharePopView.getShareDetai(Value.TYPE_SHARE, 0,null);

		mInflater = getLayoutInflater();// 获取mInflater，用于加载布局
		layout_thanks_fee.setOnClickListener(this);
		res = getResources();
		mBaiduMap = mMapView.getMap();
		iv_locate.setOnClickListener(this);
		dialog = new MyAlertDailog(this);
		position_run = new MyPosition_Run();
		position_near = new MyPositionNearByDriver();
		position_time = new MyPosition_Time();
		position_jifei = new MyPosition_jiFei();
		db_myordering = new MyOrderingDB();
		db_myorder = new MyOrderDB();
		db_jmsg = new JmsgDB();
		mIntent = getIntent();
		type_activity = mIntent.getExtras().getInt(OrderMsg.extra_type);
		// initArcMenu();
		initDrawer();
		initChat();
		if (loaddialog != null && !loaddialog.isShowing()) {
			loaddialog.show();
		}
		mInitTask = new InitTask();
		mInitTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

	}

	public class InitTask extends AsyncTask<Object, Object, Object> {
		protected Void doInBackground(Object... params) {
			switch (type_activity) {
			case 0:// 主界面跳转过来的
				list_order.clear();
				list_order.addAll(db_myordering.onReadDB_ing(
						MyOrderActivity.num_ing, true));
				break;
			case 1:// 列表跳转过来的
				list_order.clear();
				list_order.addAll(db_myordering.onReadDB_ing(
						MyOrderActivity.num_ing, true));
				extra_order_id = mIntent.getExtras().getString(
						OrderMsg.extra_order_id);
				break;
			}
			// 根据订单Id存储顺序id

			return null;
		}

		protected void onPostExecute(Object result) {
			if (list_order == null || list_order.isEmpty()) {
				MyOrderingTask.getInstance(context)
						.setOnOrderingFinishListener(StartServiceActivity.this);

			} else {
				for (int i = 0; i < list_order.size(); i++) {
					map_id.put(list_order.get(i).getOrder_id(), i);
				}
				if (extra_order_id != null) {
					try {
						viewId = map_id.get(extra_order_id);
					} catch (Exception e) {
						MyOrderingTask.getInstance(context)
								.setOnOrderingFinishListener(
										StartServiceActivity.this);
					}

				}
				initPage();
				onShowTitleStatus();
				initMap();
				if (loaddialog != null) {
					loaddialog.dismiss();
				}
			}

			super.onPostExecute(result);
		}
	};

	/**
	 * 初始化订单详情的ViewPage
	 */
	protected void initPage() {
		try {
			list_view.clear();
			map_jsmg.clear();
			// 初始化多个订单的布局状态，这里先默认为等待派车，实际要根据接口返回来的值，来显示布局样式
			for (int i = 0; i < list_order.size(); i++) {
				View order_view = mInflater.inflate(
						R.layout.item_vp_order_detail, null);// 加载布局
				list_view.add(order_view);
				// 监听客服电话跟司机电话
				((ImageButton) order_view.findViewById(R.id.ib_sjtel))
						.setOnClickListener(this);
				((ImageButton) order_view.findViewById(R.id.ib_kftel))
						.setOnClickListener(this);
				onSetContent(i, order_view);
				// 不存在该Id不添加消息，怕刷新的时候又调用了initPage，导致消息重复添加

				if (!map_jsmg.containsKey(list_order.get(i).getOrder_id())) {
					ArrayList<Map<String, String>> al_jsmg = new ArrayList<Map<String, String>>();
					al_jsmg = onRead_jsmg(list_order.get(i).getOrder_id());
					map_jsmg.put(list_order.get(i).getOrder_id(), al_jsmg);
				}
			}
			mViewPager.setAdapter(new MyPagerAdapter(list_view));// 绑定数据
			mViewPager.setCurrentItem(viewId);// 设置默认子试图
			// 加载完成，则显示，并且设置地图间距
			layout_top.setVisibility(View.VISIBLE);
			layout_startservice.setVisibility(View.VISIBLE);
			new Handler().postDelayed(new Runnable() {

				@Override
				public void run() {
					setMapCenterHeight();
					iv_locate.performClick();
				}
			}, 500);
			isCurrentService(viewId);
			mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

				@Override
				public void onPageScrolled(int arg0, float arg1, int arg2) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onPageScrollStateChanged(int position) {

				}

				@Override
				public void onPageSelected(int position) {
					for (int i = 0; i < dots_top.getChildCount(); i++) {
						dots_top.getChildAt(i).setSelected(false);
					}
					dots_top.getChildAt(position).setSelected(true);
					viewId = position;
					isCurrentService(viewId);
					onShowTitleStatus();

				}
			});
			int chat_dot_margin_lr = (int) getResources().getDimension(
					R.dimen.chat_dot_margin_lr);
			int chat_dot_wh_big = (int) getResources().getDimension(
					R.dimen.chat_dot_wh_big);
			dots_top.removeAllViews();
			for (int i = 0; i < list_view.size(); i++) {
				android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams(
						chat_dot_wh_big, chat_dot_wh_big);
				lp.leftMargin = chat_dot_margin_lr;
				lp.rightMargin = chat_dot_margin_lr;
				dots_top.addView(dotsItem(i), lp);
			}
			dots_top.getChildAt(viewId).setSelected(true);
		} catch (Exception e) {
		}
	}

	/**
	 * 弧形菜单的初始化
	 */
	private void initArcMenu() {
		// 弧形菜单
		mXCArcMenuView = (XCArcMenuView) findViewById(R.id.include_arcmenu)
				.findViewById(R.id.arcmenu);
		btn_tjdd = (ImageView) findViewById(R.id.include_arcmenu).findViewById(
				R.id.btn_tjdd);
		parent_arcmenu = (RelativeLayout) findViewById(R.id.include_arcmenu);
		mXCArcMenuView
				.setOnMenuItemClickListener(new OnMenuItemClickListener() {
					@Override
					public void onClick(View view, int pos) {
						closeArcMenu();
						String tag = (String) view.getTag();
						Toast.makeText(StartServiceActivity.this, tag,
								Toast.LENGTH_SHORT).show();
						int viewpageId = Value.ORDER_TYPE_PC;
						if (tag.equals(getString(R.string.text_express))) {
							viewpageId = Value.VIEWID_KJ;
						} else if (tag
								.equals(getString(R.string.text_carpooling2))) {
							viewpageId = Value.VIEWID_PC;
						} else if (tag
								.equals(getString(R.string.text_charteredcar2))) {
							// viewpageId = Value.VIEWID_BC;
						}
						MainAttribute main = MainAttribute.getInstance();
						main.onRestoreAttribute();
						Intent intent = new Intent();
						intent.setClass(StartServiceActivity.this,
								MainActivity.class);
						intent.putExtra(MainMsg.extra_viewpageId, viewpageId);
						intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 注意本行的FLAG设置
						startActivity(intent);
					}
				});
		mXCArcMenuView.setOnSwitchStateListener(new OnSwitchStateListener() {
			@Override
			public void onSwitchState(boolean state) {
				if (state) {
					showArcMenu();
				} else {
					closeArcMenu();
				}

			}
		});
	}

	/**
	 * 抽屉初始化
	 */
	private void initDrawer() {
		open_deawer.setOnClickListener(this);
		drawer.setOnClickListener(this);
		drawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {

			@Override
			public void onDrawerClosed() {
				// 点这里，更多订单操作。
				handle_text.setText(R.string.drawer_open);
				open_deawer.setVisibility(View.VISIBLE);
				drawer.setVisibility(View.GONE);
				isNoSliding(false);
			}
		});
		drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

			@Override
			public void onDrawerOpened() {
				// 收起对话，查看地图。
				handle_text.setText(R.string.drawer_close);
				isNoSliding(true);
			}
		});
	}

	public void isNoSliding(boolean isNo) {
		if (isSnQiangdan()) {
			isNo = true;
		}
		if (isNo) {
			dots_top.setVisibility(View.GONE);
			mViewPager.setNoScroll(true);
		} else {
			dots_top.postDelayed(new Runnable() {

				@Override
				public void run() {
					if (isSnQiangdan()) {
						dots_top.setVisibility(View.GONE);
					} else {
						dots_top.setVisibility(View.VISIBLE);
					}

				}
			}, 1000);
			mViewPager.setNoScroll(false);
		}

	}

	/**
	 * 聊天界面列表初始化
	 */
	private void initChat() {
		send_sms.setOnClickListener(this);
		image_add.setOnClickListener(this);
		image_face.setOnClickListener(this);
		btn_change_order.setOnClickListener(this);
		btn_order_detail.setOnClickListener(this);
		btn_cancel_order.setOnClickListener(this);
		mListView.setOnRefreshListenerHead(this);
		chatMessageListAdapter = new ChatMessageListAdapter(l_msg, this);
		mListView.setAdapter(chatMessageListAdapter);
		mListView.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				// if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
				// if (chat_face_container.getVisibility() == View.VISIBLE) {
				// chat_face_container.setVisibility(View.GONE);
				// }
				// if (chat_add_container.getVisibility() == View.VISIBLE) {
				// chat_add_container.setVisibility(View.GONE);
				// }
				// hideSoftInputView();
				// }
				return false;
			}
		});
	}

	/**
	 * 地图初始化
	 */
	private void initMap() {
		mMapView.showZoomControls(false);
		mMapView.showScaleControl(true);
		Message msg = new Message();
		msg.what = MSG_LOCATION;
		if (list_order != null && !list_order.isEmpty()
				&& list_order.size() > viewId) {
			int status = list_order.get(viewId).getOrder_status();
			if (status == Value.ORDER_STATUS_ONCAR) {
				msg.obj = (Boolean) false;
				mHandler.sendMessageDelayed(msg, 100);
			}
		}

	}

	@Override
	protected void initData() {
		db_line = new LineDB();
	}

	@Override
	protected void desotryItems() {
		// TODO Auto-generated method stub

	}

	/**
	 * 订单详情切换和表情页切换时，底部小圆点
	 * 
	 * @param position
	 * @return
	 */
	private RelativeLayout dotsItem(int position) {
		View layout = inflater.inflate(R.layout.dot_image, null);
		RelativeLayout iv = (RelativeLayout) layout.findViewById(R.id.face_dot);
		iv.setBackgroundDrawable(getResources().getDrawable(R.drawable.selector_circle_blue2));
		iv.setId(position);
		return iv;
	}

	@OnClick(R.id.iv_ad_exit)
	@Override
	public void onClick(View v) {
		if (!isClick)
			return;
		switch (v.getId()) {
		case R.id.iv_left:
			finish();
			break;
		case R.id.tv_right:// 取消订单
			startActivityForResult(
					new Intent(this, CancelOrderActivity.class).putExtra(
							OrderMsg.cancel_order_id, list_order.get(viewId)
									.getOrder_id()), requestCode);
//			String start_city = ToCity2.getCity(list_order.get(viewId)
//					.getLocations().getStart().getAddress());
//
//			String end_city = ToCity2.getCity(list_order.get(viewId)
//					.getLocations().getEnd().getAddress());
//			dialog.setTitle(getString(R.string.mydailog_title));
//			dialog.setContent(String.format(
//					getString(R.string.mydailog_content_cancel_order),
//					DateFormat.onDateRemove_mmss(list_order.get(viewId)
//							.getAppoint_time()), start_city, end_city));
//			dialog.setLeftButtonText(getString(R.string.mydailog_giveup_cancel));
//			dialog.setRightButtonText(getString(R.string.mydailog_confirm_cancel));
//			if (dialog != null && !dialog.isShowing()) {
//				dialog.show();
//			}
//			dialog.setOnClickLeftListener(new onClickLeftListener() {
//				@Override
//				public void onClickLeft() {
//					dialog.dismiss();
//				}
//			});
//			dialog.setOnClickRightListener(new onClickRightListener() {
//
//				@Override
//				public void onClickRight() {
//					dialog.dismiss();
//					RequestUtils.requestCancel(context, list_order.get(viewId)
//							.getOrder_id());
//
//				}
//			});

			break;
		case R.id.send_sms:// 发送消息
			// sendMsgText(input_sms.getText().toString(), I_ID,
			// DateFormat.getCurrentTime());
			// onSaveSendMsg(input_sms.getText().toString(), I_ID,
			// DateFormat.getCurrentTime());
			// input_sms.postDelayed(new Runnable() {
			//
			// @Override
			// public void run() {
			// sendMsgText("对不起", YOU_ID, DateFormat.getCurrentTime());
			// onSaveSendMsg("对不起", YOU_ID, DateFormat.getCurrentTime());
			// }
			// }, 1000);
			break;
		case R.id.image_add:// +
			hideSoftInputView();// 隐藏软键盘
			if (chat_face_container.getVisibility() == View.VISIBLE) {
				chat_face_container.setVisibility(View.GONE);
			}
			if (chat_add_container.getVisibility() == View.GONE) {
				chat_add_container.setVisibility(View.VISIBLE);
			} else {
				chat_add_container.setVisibility(View.GONE);
			}
			break;
		case R.id.image_face:// 表情
			hideSoftInputView();// 隐藏软键盘
			if (chat_add_container.getVisibility() == View.VISIBLE) {
				chat_add_container.setVisibility(View.GONE);
			}
			if (chat_face_container.getVisibility() == View.GONE) {
				chat_face_container.setVisibility(View.VISIBLE);
			} else {
				chat_face_container.setVisibility(View.GONE);
			}
			break;
		case R.id.btn_change_order:// 修改订单
			// Intent intent;
			// if (list_order.get(viewId).getOrder_type() ==
			// Value.ORDER_TYPE_KJ) {
			// intent = new Intent(this, ChangeExpressActivity.class);
			// } else {
			// intent = new Intent(this, ChangeOrderActivity.class);
			// intent.putExtra(OrderMsg.change_order_type,
			// list_order.get(viewId).getOrder_type());
			// }
			// intent.putExtra(OrderMsg.change_old_order_id, list_order
			// .get(viewId).getOrder_id());
			// ChangeAttribute change = ChangeAttribute.getInstance();
			// change.setAttribute(list_order.get(viewId));
			// startActivityForResult(intent, requestCode);
			break;
		case R.id.btn_order_detail:// 订单详情
			sendMsgText(getString(R.string.order_detail), I_ID,
					DateFormat.getCurrentTime());
			onSaveSendMsg(getString(R.string.order_detail), I_ID,
					DateFormat.getCurrentTime());
			input_sms.postDelayed(new Runnable() {

				@Override
				public void run() {
					String number_string = "";
					String name = null;
					String name2 = null;
					String start_name_s = "";
					String end_name_s = "";
					String message = null;
					boolean Is_mutiple_oncar = false;// 是否多地点上下车
					switch (list_order.get(viewId).getOrder_type()) {
					case Value.ORDER_TYPE_KJ:
						name = "  "
								+ ((list_order.get(viewId).getLocations()
										.getStart().getName().equals("")) ? getString(R.string.i)
										: list_order.get(viewId).getLocations()
												.getStart().getName());
						name2 = "  "
								+ (list_order.get(viewId).getLocations()
										.getEnd().getName()
										+ "  "
										+ FormatUtil
												.onFormatTelephone(list_order
														.get(viewId)
														.getLocations()
														.getEnd().getPhone()) + "\n");
						// 寄件信息跟收件信息
						start_name_s = getString(R.string.intercityexpress_send)
								+ "：";
						end_name_s = getString(R.string.intercityexpress_recipient)
								+ "：";
						String volume = "";
						String weight = "";
						try {
							switch (Integer.parseInt(list_order.get(viewId)
									.getLocations().getVolume())) {
							case Value.KJ_VOLUME_S:
								volume = getString(R.string.goods_small);
								break;
							case Value.KJ_VOLUME_M:
								volume = getString(R.string.goods_middle);
								break;
							case Value.KJ_VOLUME_B:
								volume = getString(R.string.goods_big);
								break;
							}
						} catch (Exception e) {
							// 转换失败，则直接显示
							volume = list_order.get(viewId).getLocations()
									.getVolume();
						}

						try {
							if (Integer.parseInt(list_order.get(viewId)
									.getLocations().getWeight()) == Value.KJ_WEIGHT_0_5) {
								weight = getString(R.string.kg_0_5);
							} else if (Integer.parseInt(list_order.get(viewId)
									.getLocations().getWeight()) == Value.KJ_WEIGHT_6_10) {
								weight = getString(R.string.kg_6_10);
							} else if (Integer.parseInt(list_order.get(viewId)
									.getLocations().getWeight()) == Value.KJ_WEIGHT_11_15) {
								weight = getString(R.string.kg_11_15);
							}
						} catch (Exception e) {
							// 转换失败，则直接显示
							weight = list_order.get(viewId).getLocations()
									.getWeight();
						}

						// number_string = "货品详情：" + weight + ";" + volume +
						// ";";
						message = getString(R.string.text_memo)
								+ list_order.get(viewId).getMessage();
						break;
					case Value.ORDER_TYPE_PC:
						name = "\n"
								+ getString(R.string.intercitycarpool_user2)
								+ ((list_order.get(viewId).getLocations()
										.getStart().getName().equals("")) ? getString(R.string.i)
										: list_order.get(viewId).getLocations()
												.getStart().getName());
						;
						start_name_s = getString(R.string.intercitycarpool_setout)
								+ "：";
						end_name_s = getString(R.string.intercitycarpool_destination)
								+ "：";
						number_string = "\n"
								+ getString(R.string.mian_number＿of＿people)
								+ "："
								+ list_order.get(viewId).getLocations()
										.getCount() + "人";
						message = "\n" + getString(R.string.text_memo)
								+ list_order.get(viewId).getMessage();
						break;
					case Value.ORDER_TYPE_BC:
						name = "\n"
								+ getString(R.string.intercitycarpool_user2)
								+ ((list_order.get(viewId).getLocations()
										.getStart().getName().equals("")) ? getString(R.string.i)
										: list_order.get(viewId).getLocations()
												.getStart().getName());
						;
						start_name_s = getString(R.string.intercitycarpool_setout)
								+ "：";
						end_name_s = getString(R.string.intercitycarpool_destination)
								+ "：";
						Is_mutiple_oncar = list_order.get(viewId)
								.getLocations().getIs_mutiple_oncar() == 1 ? true
								: false;
						number_string = "\n"
								+ getString(R.string.mian_car_number)
								+ "："
								+ String.format(getString(R.string.num_car),
										list_order.get(viewId).getLocations()
												.getCount());
						message = "\n" + getString(R.string.text_memo)
								+ list_order.get(viewId).getMessage();
						break;
					case Value.ORDER_TYPE_SN:
						name = "\n"
								+ getString(R.string.intercitycarpool_user2)
								+ ((list_order.get(viewId).getLocations()
										.getStart().getName().equals("")) ? getString(R.string.i)
										: list_order.get(viewId).getLocations()
												.getStart().getName());
						;
						start_name_s = getString(R.string.intercitycarpool_setout)
								+ "：";
						end_name_s = getString(R.string.intercitycarpool_destination)
								+ "：";
						break;
					}
					String xinxi = getString(R.string.mian_trip_time)
							+ "："
							+ list_order.get(viewId).getAppoint_time()
							+ "\n"
							+ start_name_s
							+ list_order.get(viewId).getLocations().getStart()
									.getAddress()
							+ ((name2 != null) ? name
									+ "  "
									+ FormatUtil.onFormatTelephone(list_order
											.get(viewId).getLocations()
											.getStart().getPhone()) + "\n"
									: "\n")
							+ end_name_s
							+ list_order.get(viewId).getLocations().getEnd()
									.getAddress()
							+ ((name2 == null) ? name
									+ "  "
									+ FormatUtil.onFormatTelephone(list_order
											.get(viewId).getLocations()
											.getStart().getPhone()) + "" : "")
							+ (name2 != null ? name2 : "")
							+ number_string
							+ ((message != null) ? message : "")
							+ (Is_mutiple_oncar ? "\n"
									+ getString(R.string.diff_oncar2) : "");
					sendMsgText(xinxi, YOU_ID, DateFormat.getCurrentTime());
					onSaveSendMsg(xinxi, YOU_ID, DateFormat.getCurrentTime());
				}
			}, 1000);
			break;
		case R.id.btn_cancel_order:
			ToastUtil.showToast(context, R.string.order_cancel);
			startActivityForResult(
					new Intent(this, CancelOrderActivity.class).putExtra(
							OrderMsg.cancel_order_id, list_order.get(viewId)
									.getOrder_id()), requestCode);
			break;
		case R.id.open_deawer:// 打开抽屉
			open_deawer.setVisibility(View.GONE);
			drawer.setVisibility(View.VISIBLE);
			drawer.animateOpen();
			break;
		// 拨打司机电话
		case R.id.ib_sjtel:
			// 根据viewId判断司机的电话经行拨打
			ToastUtil.showToast(context, R.string.tel_si);
			// 用intent启动拨打电话
			startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
					+ list_order.get(viewId).getDriver_phone())));
			break;
		// 拨打客服电话
		case R.id.ib_kftel:
			Tel.onTel_KF(context, list_order.get(viewId));
			break;
		case R.id.iv_locate:
			if (isService(true, 0)) {
				setCenterPoint(mApplication.latitude, mApplication.longitude,
						17);
			} else {
				setStartAndEndLevel(viewId);
			}

			break;
		case R.id.layout_thanks_fee:
			int thanksFee = 0;
			try {
				thanksFee = Integer.parseInt(FormatUtil
						.onFormatPrice(list_order.get(viewId).getPrice_Detail()
								.getSchedule_fee()));
			} catch (Exception e) {
			}
			if (thanksFee >= Value.ThanksFeeMax) {
				switch(VersionUtils.getVersionType(context)){
				case bbx:
					ToastUtil.showToast(context,context.getString(R.string.thanks_fee_max));
					break;
				case tianshang:
					ToastUtil.showToast(context,context.getString(R.string.thanks_fee_max2));
					break;
				}
			} else {
				int thanks_fee_jine_id = 0;
				switch(VersionUtils.getVersionType(context)){
				case bbx:
					thanks_fee_jine_id=R.string.thanks_fee_jine;
					break;
				case tianshang:
					thanks_fee_jine_id=R.string.thanks_fee_jine2;
					break;
				}
				final CustomPicker pvCustom = DatePicker2.getInstance(this).showNum(thanksFee+1,Value.ThanksFeeMax);
				pvCustom.show();
				pvCustom.setCustomSelectListener(new CustomPicker.OnCustomSelectListener() {
					@Override
					public void onCustomSelect(int[] index) {
						int i=0;
						RequestUtils.requestAddThanks(context,
								list_order.get(viewId).getOrder_id(),
								Integer.parseInt(pvCustom.getData()[i].get(index[i])+"") * 100,
								list_order.get(viewId).getLine_id(),
								list_order.get(viewId).getOrder_type());
					}
				});
//				DatePicker.getInstance(this).onShowPeople(v, thanksFee+1,
//						Value.ThanksFeeMax,
//						this.getString(thanks_fee_jine_id), null);
//				DatePicker.getInstance(this).setOnConfirmListener(
//						new OnConfirmListener() {
//							@Override
//							public void onConfirm(List<String> list,
//									WheelView people) {
//								RequestUtils.requestAddThanks(context,
//										list_order.get(viewId).getOrder_id(),
//										Integer.parseInt(list.get(people
//												.getCurrentItem())) * 100,
//										list_order.get(viewId).getLine_id(),
//										list_order.get(viewId).getOrder_type());
//							}
//						});
			}

			break;
		case R.id.iv_ad_exit:
			layout_ad.setVisibility(View.GONE);
			new Handler().postDelayed(new Runnable() {

				@Override
				public void run() {
					setMapCenterHeight();
					iv_locate.performClick();
				}
			}, 500);
			break;
		default:
			super.onClick(v);
			break;
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if (null == mMyFacePagerAdapter) {
			initExpression();
			List<List<Expression>> lists = initGridViewData();// 填充GridView数据
			grids = new ArrayList<GridView>();
			int gv_padding_lr = (int) getResources().getDimension(
					R.dimen.chat_gv_padding_lr);
			int gv_padding_bt = (int) getResources().getDimension(
					R.dimen.chat_gv_padding_bt);
			int gv_spacing = (int) getResources().getDimension(
					R.dimen.chat_gv_spacing);
			int chat_dot_margin_lr = (int) getResources().getDimension(
					R.dimen.chat_dot_margin_lr);
			int chat_dot_wh = (int) getResources().getDimension(
					R.dimen.chat_dot_wh);
			for (int i = 0; i < lists.size(); i++) {
				List<Expression> l = lists.get(i);
				if (null != l) {
					// --生成当前GridView--//
					final GridView gv = new GridView(this);
					gv.setLayoutParams(new LayoutParams(
							LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
					gv.setNumColumns(columns);
					gv.setGravity(Gravity.CENTER);
					gv.setPadding(gv_padding_lr, gv_padding_bt, gv_padding_lr,
							0);
					gv.setHorizontalSpacing(gv_spacing);
					gv.setVerticalSpacing(gv_spacing);
					ExpressionImageAdapter expressionImageAdapter = new ExpressionImageAdapter(
							this, l);
					gv.setAdapter(expressionImageAdapter);
					// --点击列表事件处理--//
					gv.setOnItemClickListener(new OnItemClickListener() {
						/*
						 * (non-Javadoc)
						 * 
						 * @see android.widget.AdapterView.OnItemClickListener#
						 * onItemClick(android.widget.AdapterView,
						 * android.view.View, int, long)
						 */
						@Override
						public void onItemClick(AdapterView<?> arg0, View arg1,
								int arg2, long arg3) {
							Expression e = (Expression) gv
									.getItemAtPosition(arg2);
							LogUtils.v("_____________", "点击表情_" + e.code);
							int index = input_sms.getSelectionStart();
							Editable edit = input_sms.getEditableText();// 获取EditText的文字
							String content_all = edit.toString();
							String content_forward = content_all.substring(0,
									index);
							LogUtils.v("_____________", "content_all = "
									+ content_all + "|content_forward = "
									+ content_forward + "|");
							String reg = "\\[#[1-9][0-9]?\\]";
							if (e.getDrableId() < 0) {// 点击删除按钮
								if (index > 0) {
									boolean delExpression = false;
									Pattern p = Pattern.compile(reg);
									Matcher matcher = p
											.matcher(content_forward);
									// 因为这里表情代码最长为5，所以这里减5
									boolean found = false;
									if (content_forward.length() >= 4) {// 如果光标前字符少于4个，说明不可能为表情
										if (content_forward.length() == 4) {
											found = matcher
													.find(content_forward
															.length() - 4);
										} else {
											found = matcher
													.find(content_forward
															.length() - 5);
										}
										if (found) {
											String flag = matcher.group();
											if (content_forward.substring(
													content_forward.length()
															- flag.length(),
													content_forward.length())
													.equals(flag)) {
												delExpression = true;
												edit.delete(
														index - flag.length(),
														index);
											}
										}
									}
									if (!delExpression) {
										edit.delete(index - 1, index);
									}
								}
							} else {
								ImageSpan imageSpan = new ImageSpan(
										BitmapFactory.decodeResource(
												getResources(), e.drableId));
								SpannableString spannableString = new SpannableString(
										e.code);
								spannableString.setSpan(imageSpan, 0,
										e.code.length(),
										Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

								LogUtils.v("_____________", "spannableString="
										+ spannableString.toString()
										+ "__index=" + index);

								if (index < 0 || index >= edit.length()) {
									edit.append(spannableString);
								} else {
									edit.insert(index, spannableString);
								}
							}
						}
					});
					grids.add(gv);
					// --生成索引图--//
					android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams(
							chat_dot_wh, chat_dot_wh);
					lp.leftMargin = chat_dot_margin_lr;
					lp.rightMargin = chat_dot_margin_lr;
					dots_face.addView(dotsItem(i), lp);
					dots_face.getChildAt(0).setSelected(true);
				}
			}
			mMyFacePagerAdapter = new MyFacePagerAdapter(grids);
			face_viewpager.setAdapter(mMyFacePagerAdapter);
			face_viewpager.setOnPageChangeListener(new OnPageChangeListener() {

				@Override
				public void onPageScrolled(int arg0, float arg1, int arg2) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onPageScrollStateChanged(int arg0) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onPageSelected(int position) {
					for (int i = 0; i < dots_face.getChildCount(); i++) {
						dots_face.getChildAt(i).setSelected(false);
					}
					dots_face.getChildAt(position).setSelected(true);

				}
			});
			dots_face.getChildAt(0).setSelected(true);
		}

		// tv_chat_title.setText(Html.fromHtml("<img src=\""+2130837523+"\" />",
		// imageGetter_resource, null));
		//注册传感器
//		mSensorManager.registerListener(this, mAccelerometer,SensorManager.SENSOR_DELAY_NORMAL);
				//启动定位
		mApplication.onStartLocation();
	}

	/**
	 * 填充GridView所需要的数据
	 */
	private List<List<Expression>> initGridViewData() {
		List<List<Expression>> lists = new ArrayList<List<Expression>>();
		List<Expression> list = null;
		for (int i = 0; i < expressionList.size(); i++) {
			if (i % pageExpressionCount == 0) {// 一页数据已填充完成
				if (null != list) {
					list.add(new Expression(-1, "backSpace"));// 添加删除键
					lists.add(list);
				}
				list = new ArrayList<Expression>();
			}
			list.add(expressionList.get(i));
			// 最后一个表情，并且不是当前页最后一个表情时，后面添加删除键
			if (i >= expressionList.size() - 1) {
				list.add(new Expression(-1, "backSpace"));// 添加删除键
				lists.add(list);
			}
		}
		return lists;
	}

	/**
	 * 初始化表情信息
	 */
	public static void initExpression() {
		Expression exp1 = new Expression(R.drawable.e_1, "[#1]");
		Expression exp2 = new Expression(R.drawable.e_2, "[#2]");
		Expression exp3 = new Expression(R.drawable.e_3, "[#3]");
		Expression exp4 = new Expression(R.drawable.e_4, "[#4]");
		Expression exp5 = new Expression(R.drawable.e_5, "[#5]");
		Expression exp6 = new Expression(R.drawable.e_6, "[#6]");
		Expression exp7 = new Expression(R.drawable.e_7, "[#7]");
		Expression exp8 = new Expression(R.drawable.e_8, "[#8]");
		Expression exp9 = new Expression(R.drawable.e_9, "[#9]");
		Expression exp10 = new Expression(R.drawable.e_10, "[#10]");

		Expression exp11 = new Expression(R.drawable.e_11, "[#11]");
		Expression exp12 = new Expression(R.drawable.e_12, "[#12]");
		Expression exp13 = new Expression(R.drawable.e_13, "[#17]");
		Expression exp14 = new Expression(R.drawable.e_14, "[#14]");
		Expression exp15 = new Expression(R.drawable.e_15, "[#15]");
		Expression exp16 = new Expression(R.drawable.e_16, "[#16]");
		Expression exp17 = new Expression(R.drawable.e_17, "[#17]");
		Expression exp18 = new Expression(R.drawable.e_18, "[#18]");
		Expression exp19 = new Expression(R.drawable.e_19, "[#19]");
		Expression exp20 = new Expression(R.drawable.e_20, "[#20]");

		Expression exp21 = new Expression(R.drawable.e_21, "[#21]");
		Expression exp22 = new Expression(R.drawable.e_22, "[#22]");
		Expression exp23 = new Expression(R.drawable.e_23, "[#23]");
		Expression exp24 = new Expression(R.drawable.e_24, "[#24]");
		Expression exp25 = new Expression(R.drawable.e_25, "[#25]");
		Expression exp26 = new Expression(R.drawable.e_26, "[#26]");
		Expression exp27 = new Expression(R.drawable.e_27, "[#27]");
		Expression exp28 = new Expression(R.drawable.e_28, "[#28]");
		Expression exp29 = new Expression(R.drawable.e_29, "[#29]");
		Expression exp30 = new Expression(R.drawable.e_30, "[#30]");

		Expression exp31 = new Expression(R.drawable.e_31, "[#31]");
		Expression exp32 = new Expression(R.drawable.e_32, "[#32]");
		Expression exp33 = new Expression(R.drawable.e_33, "[#33]");
		Expression exp34 = new Expression(R.drawable.e_34, "[#34]");
		Expression exp35 = new Expression(R.drawable.e_35, "[#35]");
		Expression exp36 = new Expression(R.drawable.e_36, "[#36]");
		Expression exp37 = new Expression(R.drawable.e_37, "[#37]");
		Expression exp38 = new Expression(R.drawable.e_38, "[#38]");
		Expression exp39 = new Expression(R.drawable.e_39, "[#39]");
		Expression exp40 = new Expression(R.drawable.e_40, "[#40]");

		Expression exp41 = new Expression(R.drawable.e_41, "[#41]");
		Expression exp42 = new Expression(R.drawable.e_42, "[#42]");
		Expression exp43 = new Expression(R.drawable.e_43, "[#43]");
		Expression exp44 = new Expression(R.drawable.e_44, "[#44]");
		Expression exp45 = new Expression(R.drawable.e_45, "[#45]");
		Expression exp46 = new Expression(R.drawable.e_46, "[#46]");
		Expression exp47 = new Expression(R.drawable.e_47, "[#47]");
		Expression exp48 = new Expression(R.drawable.e_48, "[#48]");
		Expression exp49 = new Expression(R.drawable.e_49, "[#49]");
		Expression exp50 = new Expression(R.drawable.e_50, "[#50]");

		Expression exp51 = new Expression(R.drawable.e_51, "[#51]");
		Expression exp52 = new Expression(R.drawable.e_52, "[#52]");
		Expression exp53 = new Expression(R.drawable.e_53, "[#53]");
		Expression exp54 = new Expression(R.drawable.e_54, "[#54]");
		Expression exp55 = new Expression(R.drawable.e_55, "[#55]");
		Expression exp56 = new Expression(R.drawable.e_56, "[#56]");
		Expression exp57 = new Expression(R.drawable.e_57, "[#57]");
		Expression exp58 = new Expression(R.drawable.e_58, "[#58]");
		Expression exp59 = new Expression(R.drawable.e_59, "[#59]");
		Expression exp60 = new Expression(R.drawable.e_60, "[#60]");

		Expression exp61 = new Expression(R.drawable.e_61, "[#61]");
		Expression exp62 = new Expression(R.drawable.e_62, "[#62]");
		Expression exp63 = new Expression(R.drawable.e_63, "[#63]");
		Expression exp64 = new Expression(R.drawable.e_64, "[#64]");

		expressionList.add(exp1);
		expressionList.add(exp2);
		expressionList.add(exp3);
		expressionList.add(exp4);
		expressionList.add(exp5);
		expressionList.add(exp6);
		expressionList.add(exp7);
		expressionList.add(exp8);
		expressionList.add(exp9);
		expressionList.add(exp10);

		expressionList.add(exp11);
		expressionList.add(exp12);
		expressionList.add(exp13);
		expressionList.add(exp14);
		expressionList.add(exp15);
		expressionList.add(exp16);
		expressionList.add(exp17);
		expressionList.add(exp18);
		expressionList.add(exp19);
		expressionList.add(exp20);

		expressionList.add(exp21);
		expressionList.add(exp22);
		expressionList.add(exp23);
		expressionList.add(exp24);
		expressionList.add(exp25);
		expressionList.add(exp26);
		expressionList.add(exp27);
		expressionList.add(exp28);
		expressionList.add(exp29);
		expressionList.add(exp30);

		expressionList.add(exp31);
		expressionList.add(exp32);
		expressionList.add(exp33);
		expressionList.add(exp34);
		expressionList.add(exp35);
		expressionList.add(exp36);
		expressionList.add(exp37);
		expressionList.add(exp38);
		expressionList.add(exp39);
		expressionList.add(exp40);

		expressionList.add(exp41);
		expressionList.add(exp42);
		expressionList.add(exp43);
		expressionList.add(exp44);
		expressionList.add(exp45);
		expressionList.add(exp46);
		expressionList.add(exp47);
		expressionList.add(exp48);
		expressionList.add(exp49);
		expressionList.add(exp50);

		expressionList.add(exp51);
		expressionList.add(exp52);
		expressionList.add(exp53);
		expressionList.add(exp54);
		expressionList.add(exp55);
		expressionList.add(exp56);
		expressionList.add(exp57);
		expressionList.add(exp58);
		expressionList.add(exp59);
		expressionList.add(exp60);

		expressionList.add(exp61);
		expressionList.add(exp62);
		expressionList.add(exp63);
		expressionList.add(exp64);
	}

	/**
	 * 执行发送消息 文本类型
	 * 
	 * @param content
	 */
	public void sendMsgText(String content, int userID, String time) {
		ChatMessage cm = new ChatMessage();
		cm.chatMsg = content;
		cm.nickName = "nickName_I";
		cm.userID = userID;
		cm.time = time;
		LogUtils.v("_____________", "msg=" + cm.chatMsg + "|nickName="
				+ cm.nickName + "|userID=" + cm.userID);
		this.l_msg.add(cm);
		if (null != chatMessageListAdapter) {
			chatMessageListAdapter.setL(l_msg);
			chatMessageListAdapter.notifyDataSetChanged();
		}
		input_sms.setText("");
	}

	public void onSaveSendMsg(String content, int userID, String time) {
		// 存在这个Id
		if (map_jsmg.containsKey(list_order.get(viewId).getOrder_id())) {
			ArrayList<Map<String, String>> list_jsmg = map_jsmg.get(list_order
					.get(viewId).getOrder_id());
			Map<String, String> map = new HashMap<String, String>();
			map.put(MSG_CONTENT, content);
			map.put(MSG_USER, userID + "");
			map.put(DBcolumns.MESSAGE_TIME, time);
			map.put(DBcolumns.MESSAGE_TYPE, ONLINE_CHAT + "");
			map.put(DBcolumns.MESSAGE_TIME, DateFormat.getCurrentTime());
			list_jsmg.add(map);
			map_jsmg.put(list_order.get(viewId).getOrder_id(), list_jsmg);
		}
	}

	/**
	 * 隐藏软键盘
	 */
	public void hideSoftInputView() {
		InputMethodManager manager = ((InputMethodManager) this
				.getSystemService(Activity.INPUT_METHOD_SERVICE));
		if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
			if (getCurrentFocus() != null)
				manager.hideSoftInputFromWindow(getCurrentFocus()
						.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
		}
	}

	/**
	 * 展开弧形菜单
	 */
	public void showArcMenu() {
		isClick = false;
		parent_arcmenu.setBackgroundColor(getResources().getColor(
				R.color.transparent_80));
		layout_top.setForeground(getResources().getDrawable(
				R.color.transparent_80));
		btn_tjdd.setImageDrawable(getResources().getDrawable(
				R.drawable.btn_tjdd_cl));
		layout_top.setClickable(true);
		parent_arcmenu.setClickable(true);
	}

	/**
	 * 关闭弧形菜单
	 */
	public void closeArcMenu() {
		isClick = true;
		parent_arcmenu.setBackgroundColor(getResources().getColor(
				R.color.transparent));
		layout_top.setForeground(getResources()
				.getDrawable(R.color.transparent));
		btn_tjdd.setImageDrawable(getResources().getDrawable(
				R.drawable.btn_tjdd));
		layout_top.setClickable(false);
		parent_arcmenu.setClickable(false);
	}

	/**
	 * 监听返回键
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			// hideSoftInputView();
			// if (chat_face_container.getVisibility() == View.VISIBLE) {
			// chat_face_container.setVisibility(View.GONE);
			// } else if (chat_add_container.getVisibility() == View.VISIBLE) {
			// chat_add_container.setVisibility(View.GONE);
			// } else {
			// finish();
			// }
			if (!isSnQiangdan())
				finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	/**
	 * 聊天记录刷新
	 */
	@Override
	public void onRefresh() {
		mListView.onRefreshCompleteHeader();

	}

	/**
	 * 设置显示内容,id为顺序Id
	 */
	public void onSetContent(int id, final View v) {
		((ImageButton) include_service_wait.findViewById(R.id.ib_kftel))
				.setOnClickListener(this);
		int status = list_order.get(id).getOrder_status();
		// 未处理和已入队，重新入队，改派，都归为，等待派车
		if (IsSnQiangDan.isWait(status)) {
			// 关闭原本服务模式展开详情
			closeDetail();

			// 订单时间
			((TextView) v.findViewById(R.id.tv_time)).setText(DateFormat
					.onDateRemove_ss(list_order.get(id).getAppoint_time()));
			// 订单类型，拼车或者包车或者快件
			int type = list_order.get(id).getOrder_type();
			String type_s = "";
			switch (type) {
			case Value.ORDER_TYPE_PC:
				type_s = getString(R.string.pc);
				((TextView) v.findViewById(R.id.tv_count)).setText(String
						.format(getString(R.string.num), list_order.get(id)
								.getLocations().getCount()));
				break;
			case Value.ORDER_TYPE_BC:
				type_s = getString(R.string.bc);
				((TextView) v.findViewById(R.id.tv_count)).setText(String
						.format(getString(R.string.num_car), list_order.get(id)
								.getLocations().getCount()));
				break;
			case Value.ORDER_TYPE_KJ:
				// ((TextView) v.findViewById(R.id.tv_count)).setText(String
				// .format(getString(R.string.num_jian), list_order
				// .get(id).getLocations().getCount()));

				type_s = getString(R.string.kj);
				break;
			case Value.ORDER_TYPE_SN:
				((TextView) v.findViewById(R.id.tv_count))
						.setVisibility(View.GONE);
				type_s = getString(R.string.sn);
				break;
			}
			switch (list_order.get(id).getOrder_origin()) {
			case Value.ORDER_ORIGIN:// 爱心直通车
				((TextView) v.findViewById(R.id.tv_count))
						.setVisibility(View.GONE);
				type_s = getString(R.string.aixin);
				((ImageButton) v.findViewById(R.id.ib_kftel))
						.setVisibility(View.GONE);
				break;
			case Value.ORDER_ORIGIN_SF:// 顺风车
				type_s = getString(R.string.sf);
				break;
			}
			((TextView) v.findViewById(R.id.tv_order_type)).setText(type_s);
			// 出发地
			((TextView) v.findViewById(R.id.tv_start)).setText(list_order
					.get(id).getLocations().getStart().getAddress());
			// 目的地
			((TextView) v.findViewById(R.id.tv_end)).setText(list_order.get(id)
					.getLocations().getEnd().getAddress());
		}
		// 已指派和已上车，已下车，都归为，服务中
		else if (isService(false, id)) {
			((RatingBar) v.findViewById(R.id.rb_rating)).setRating(FormatUtil
					.onFormatStar((float) list_order.get(id).getDriver_star()));
			((TextView) v.findViewById(R.id.tv_rating)).setText(FormatUtil
					.onFormatStar((float) list_order.get(id).getDriver_star())
					+ "");
			layout_wait = ((LinearLayout) v.findViewById(R.id.layout_wait));
			layout_wait.setVisibility(View.GONE);
			layout_service = ((LinearLayout) v
					.findViewById(R.id.layout_service));
			layout_service.setVisibility(View.VISIBLE);
			layout_service.setOnTouchListener(new OnTouchListener() {

				@Override
				public boolean onTouch(View v, MotionEvent event) {
					int move_y = 0;
					if (event.getAction() == MotionEvent.ACTION_DOWN) {
						down_y = (int) event.getY();
					}
					if (event.getAction() == MotionEvent.ACTION_UP) {
						move_y = (int) event.getY();
						if ((move_y - down_y) > 50) {
							if (!isOpenServiceWait&&!drawer.isOpened()) {
								if (include_service_wait.getVisibility() == View.GONE) {
									showDetail();
								}
							}
						} else if ((down_y - move_y) > 50) {
							if (isOpenServiceWait&&!drawer.isOpened()) {
								if (include_service_wait.getVisibility() == View.VISIBLE) {
									closeDetail();
								}
							}
						}
					}
					return false;
				}
			});
			include_service_wait.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					if (!isOpenServiceWait || !isClick)
						return;
					if (include_service_wait.getVisibility() == View.VISIBLE) {
						// closeDetail();
					}
				}
			});
			((TextView) v.findViewById(R.id.tv_driver_name)).setText(list_order
					.get(id).getDriver_name());
			((TextView) v.findViewById(R.id.tv_car_No)).setText(list_order.get(
					id).getCar_NO());
		}
	}

	/**
	 * 展开详情
	 */
	public void showDetail() {
		isNoSliding(true);
		isOpenServiceWait = true;
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				setVisibility(include_service_wait, View.VISIBLE);
			}
		}, 200);
	}

	/**
	 * 关闭详情
	 */
	public void closeDetail() {
		isNoSliding(false);
		isOpenServiceWait = false;
		setVisibility(include_service_wait, View.GONE);
	}

	/**
	 * 感谢费的显示隐藏
	 */
	public void showAndHidThanksFee() {
		int status = list_order.get(viewId).getOrder_status();
		int order_type = list_order.get(viewId).getOrder_type();
		if (IsSnQiangDan.isWait(status) && order_type == Value.ORDER_TYPE_SN) {
			switch(VersionUtils.getVersionType(context)){
			case bbx:
				tv_thanks_fee_text.setText(getString(R.string.schedule_fee));
				break;
			case tianshang:
				tv_thanks_fee_text.setText(getString(R.string.schedule_fee2));
				break;
			}
			layout_thanks_fee.setVisibility(View.VISIBLE);
		} else {
			layout_thanks_fee.setVisibility(View.GONE);
		}

	}

	/**
	 * 显示标题状态
	 */
	public void onShowTitleStatus() {
		// 判断标题
		if (isService(true, 0)) {
			setTitle(R.string.service_title);
		} else {
			setTitle(!isSnQiangdan(), getString(R.string.wait_title), -1,
					getString(R.string.title_right_cancel_order));
		}
	}

	/**
	 * 判断服务中的界面，已指派跟已上车 如current==true,id随便传 current==false,,要传指定的viewid
	 */
	public boolean isService(boolean current, int id) {
		if (list_order != null && !list_order.isEmpty()
				&& list_order.size() > viewId) {
			int status = list_order.get(current ? viewId : id)
					.getOrder_status();
			if (status == Value.ORDER_STATUS_ASSiIGN
					|| status == Value.ORDER_STATUS_ONCAR) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 判断是否是市内抢到模式
	 */
	public boolean isSnQiangdan() {
		if (list_order != null && !list_order.isEmpty())
			if (IsSnQiangDan.isSnQiangDan(list_order.get(viewId))) {
				return true;
			}
		return false;
	}

	/**
	 * 判断当前页面是否是服务状态。也是初始化一下地图数据，消息数据。
	 */
	public void isCurrentService(final int ViewId) {
		mHandler.removeCallbacks(position_jifei);
		if (list_order == null || list_order.isEmpty()
				|| ViewId > (list_order.size() - 1)) {
			return;
		}
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				setStartAndEndLevel(ViewId);
			}
		}, 500);
		/*--------设置服务中的等待--------------*/
		int status = list_order.get(ViewId).getOrder_status();
		if (IsSnQiangDan.isWait(status)) {
			btn_cancel_order.setVisibility(View.GONE);
			// btn_change_order.setVisibility(View.VISIBLE);
			tv_estimat_time.setVisibility(View.VISIBLE);
			long appoint = DateFormat.onDate_Long(list_order.get(viewId)
					.getAppoint_time());
			long time = DateFormat.getTime();
			long diff_time = appoint - time;
			if (list_order.get(viewId).getOrder_type() == Value.ORDER_TYPE_SN) {
				if (diff_time < IsSnQiangDan.Jiange_time) {
					tv_estimat_time.setVisibility(View.GONE);
				} else {
					tv_estimat_time.setText(String.format(
							getString(R.string.estimat_time3),
							IsSnQiangDan.shijiJiange));
				}
			} else {
				if (diff_time < 1000 * 60 * estimat_time) {
					tv_estimat_time.setText(R.string.estimat_time2);
				} else {
					tv_estimat_time.setText(String.format(
							res.getString(R.string.estimat_time),
							DateFormat.onCNTimeRemove_mmdd(appoint - 1000 * 60
									* estimat_time)));
				}
			}

		} else if (isService(true, 0)) {
			btn_cancel_order.setVisibility(View.VISIBLE);
			if (status == Value.ORDER_STATUS_ONCAR) {
				btn_cancel_order.setVisibility(View.GONE);
				// btn_change_order.setVisibility(View.GONE);
			}
			tv_estimat_time.setVisibility(View.GONE);
		}
		((ImageButton) include_service_wait.findViewById(R.id.ib_kftel))
				.setOnClickListener(this);
		((TextView) include_service_wait.findViewById(R.id.tv_time))
				.setText(DateFormat.onDateRemove_ss(list_order.get(ViewId)
						.getAppoint_time()));
		// 订单类型，拼车或者包车或者快件
		int type = list_order.get(ViewId).getOrder_type();
		String type_s = "";
		double price = list_order.get(ViewId).getPrice();
		//需要支付价格
		double actual_price=0;
		/**先隐藏价格信息，到后面才显示*/
		layout_price.setVisibility(View.INVISIBLE);
		int coupon_type = CouponUtils.coupon_type_0;
		//优惠劵金额
		String coupon_sum = "0";		
		//判断是下单立减还是优惠劵
		int sale_type=0;
		try{sale_type=list_order.get(viewId).getPrice_Detail().getSaleType();}catch(Exception e){}
		switch(sale_type){
		case UsableSale.sale_type_no:
			try {
				coupon_type = Integer.parseInt(list_order.get(viewId).getDiscount()
						.getType());
			} catch (Exception e) {
			}
			try {
				double CouponSum=list_order.get(viewId).getDiscount().getSum()*100;
				actual_price=price-CouponSum;
				coupon_sum=FormatUtil.onFormatPrice(CouponSum);
			} catch (Exception e) {
			}
			break;
		case UsableSale.sale_type_submit:
		case UsableSale.sale_type_online:
			try{
				double CouponSum=list_order.get(viewId).getPrice_Detail().getSaleAmount();
				actual_price=price-CouponSum;
				coupon_sum=FormatUtil.onFormatPrice(CouponSum);
			}catch(Exception e){}
			
			break;
		}
		switch (coupon_type) {
		case CouponUtils.coupon_type_0:
		case CouponUtils.coupon_type_3:
			tv_price.setText(String.format(getString((sale_type==UsableSale.sale_type_no)?R.string.service_price:R.string.service_price3),
					FormatUtil.onFormatPrice(price), coupon_sum));
			price_text.setText(getString(R.string.price_text));
			tv_price.setVisibility(View.VISIBLE);
			price_text.setTextColor(getResources().getColor(R.color.blue));
			break;
		case CouponUtils.coupon_type_1:
			tv_price.setText(String.format(
					getString((sale_type==UsableSale.sale_type_no)?R.string.service_price:R.string.service_price3),
					FormatUtil.onFormatPrice(price),
					CouponUtils.getZhekouSum(price,
							Double.parseDouble(coupon_sum))));
			price_text.setText(getString(R.string.price_text));
			tv_price.setVisibility(View.VISIBLE);
			price_text.setTextColor(getResources().getColor(R.color.blue));
			break;
		case CouponUtils.coupon_type_2:
			tv_price.setText(String.format(
					getString((sale_type==UsableSale.sale_type_no)?R.string.service_price:R.string.service_price3),
					FormatUtil.onFormatPrice(price),
					CouponUtils.getTiyanSum(price,
							Double.parseDouble(coupon_sum))));
			price_text.setText(getString(R.string.price_text));
			tv_price.setVisibility(View.VISIBLE);
			price_text.setTextColor(getResources().getColor(R.color.blue));
			break;
		}
		tv_total_price.setText(FormatUtil.onFormatPrice(actual_price));
		switch (type) {
		case Value.ORDER_TYPE_PC:
			type_s = getString(R.string.pc);

			((TextView) include_service_wait.findViewById(R.id.tv_count))
					.setText(String.format(getString(R.string.num), list_order
							.get(ViewId).getLocations().getCount()));
			break;
		case Value.ORDER_TYPE_BC:
			type_s = getString(R.string.bc);

			((TextView) include_service_wait.findViewById(R.id.tv_count))
					.setText(String.format(getString(R.string.num_car),
							list_order.get(ViewId).getLocations().getCount()));
			break;
		case Value.ORDER_TYPE_KJ:

			// ((TextView) include_service_wait.findViewById(R.id.tv_count))
			// .setText(String.format(getString(R.string.num_jian),
			// list_order.get(ViewId).getLocations().getCount()));
			type_s = getString(R.string.kj);
			break;
		case Value.ORDER_TYPE_SN:
			((TextView) include_service_wait.findViewById(R.id.tv_count))
					.setVisibility(View.GONE);
			type_s = getString(R.string.sn);
			// 如果是是计费的
			if (list_order.get(viewId).getCalcType() == CarType.CALC_TYPE_jifei) {
				
			}
			// 如果是打表，则文字显示按计价表算
			else{
				coupon_type = CouponUtils.coupon_type_0;
				try {
					coupon_type = Integer.parseInt(list_order.get(viewId)
							.getDiscount().getType());
				} catch (Exception e) {
				}
				switch (coupon_type) {
				case CouponUtils.coupon_type_0:
				case CouponUtils.coupon_type_3:
					tv_price.setVisibility(View.VISIBLE);
					tv_price.setText(getString(R.string.service_price2));
					tv_total_price.setText(coupon_sum + "");
					price_text.setText(getString(R.string.price_text));
					price_text.setTextColor(getResources().getColor(
							R.color.blue));
					break;
				case CouponUtils.coupon_type_1:
					tv_price.setVisibility(View.VISIBLE);
					tv_price.setText(getString(R.string.service_price2_zhekou));
					tv_total_price.setText(Double.parseDouble(coupon_sum) / 10
							+ "");
					price_text.setText(getString(R.string.unit_zhekou));
					price_text.setTextColor(getResources().getColor(
							R.color.blue));
					break;
				case CouponUtils.coupon_type_2:
					tv_price.setVisibility(View.GONE);
					tv_total_price.setText(coupon_sum + "");
					price_text.setTextColor(getResources().getColor(
							R.color.text_nor));
					price_text
							.setText(getString(R.string.service_price2_tiyan));
					break;
				}
				tv_price.setText(getString(R.string.service_price2));
				tv_total_price.setText(coupon_sum + "");
			}
			break;
		}
		// 计费的，没15秒更新一次订单列表
		if (list_order.get(viewId).getCalcType() == CarType.CALC_TYPE_jifei) {
			mHandler.postDelayed(position_jifei, 0);
			//不是已上车才显示预估计
			if (list_order.get(viewId).getOrder_status() != Value.ORDER_STATUS_OFFCAR) {
			try{
			   setJifeiPrice(list_order.get(viewId).getPrice_Detail().getformula_price(),false);
			}catch(Exception e){}
			}
		}
		/**显示价格信息*/
		layout_price.setVisibility(View.VISIBLE);
		// 显示爱心直通车,隐藏客服
		if (list_order.get(ViewId).getOrder_origin() == Value.ORDER_ORIGIN) {
			((ImageButton) include_service_wait.findViewById(R.id.ib_kftel))
					.setVisibility(View.GONE);
			((TextView) include_service_wait.findViewById(R.id.tv_count))
					.setVisibility(View.GONE);
			type_s = getString(R.string.aixin);
			tv_estimat_time.setVisibility(View.GONE);
		} else {
			if (list_order.get(ViewId).getOrder_origin() == Value.ORDER_ORIGIN_SF) {
				type_s = getString(R.string.sf);
			}
			((ImageButton) include_service_wait.findViewById(R.id.ib_kftel))
					.setVisibility(View.VISIBLE);
		}
		((TextView) include_service_wait.findViewById(R.id.tv_order_type))
				.setText(type_s);
		// 出发地

		((TextView) include_service_wait.findViewById(R.id.tv_start))
				.setText(list_order.get(ViewId).getLocations().getStart()
						.getAddress());
		// 目的地
		((TextView) include_service_wait.findViewById(R.id.tv_end))
				.setText(list_order.get(ViewId).getLocations().getEnd()
						.getAddress());

		// 附近司机覆盖物
		if (list_near_marker != null) {
			for (int i = 0; i < list_near_marker.size(); i++) {
				list_near_marker.get(i).remove();
			}
		}
		// 司机覆盖物
		if (mMarkerA != null) {
			mMarkerA.remove();
		}
		// 市内覆盖物
		if (mMarkerSn != null) {
			mMarkerSn.remove();
		}
		if (mMarker_start != null) {
			mMarker_start.remove();
		}
		if (mMarker_end != null) {
			mMarker_end.remove();
		}
		// 隐藏标注
		if (mBaiduMap != null)
			mBaiduMap.hideInfoWindow();
		removeHandler();
		onLocationEnabled(true);
		isNoSliding(false);
		if (isService(true, 0) || status == Value.ORDER_STATUS_OFFCAR) {
			// 已上车跟已下车不显示当前位置
			if (status != Value.ORDER_STATUS_ASSiIGN) {
				onLocationEnabled(false);
			}
			sn_position_list.clear();
			getDriverLocation(list_order.get(ViewId).getDriver_id());
		} else {
			if (isSnQiangdan()) {
				setSnMap();
			} else {
				// 起始点
				LatLng ll_start = new LatLng(list_order.get(ViewId)
						.getLocations().getStart().getLocation().getLat(),
						list_order.get(ViewId).getLocations().getStart()
								.getLocation().getLng());
				OverlayOptions oo_start = new MarkerOptions()
						.position(ll_start).icon(bd_start).zIndex(9)
						.draggable(false);
				if (mBaiduMap != null)
					mMarker_start = (Marker) (mBaiduMap.addOverlay(oo_start));
				// 终点
				LatLng ll_end = new LatLng(list_order.get(ViewId)
						.getLocations().getEnd().getLocation().getLat(),
						list_order.get(ViewId).getLocations().getEnd()
								.getLocation().getLng());
				OverlayOptions oo_end = new MarkerOptions().position(ll_end)
						.icon(bd_end).zIndex(9).draggable(false);
				if (mBaiduMap != null)
					mMarker_end = (Marker) (mBaiduMap.addOverlay(oo_end));
			}

		}
		double thanks_fee = list_order.get(viewId).getPrice_Detail()
				.getSchedule_fee();
		if (thanks_fee == 0) {
			tv_thanks_fee.setVisibility(View.GONE);
		} else {
			tv_thanks_fee.setVisibility(View.VISIBLE);
			tv_thanks_fee.setText(FormatUtil.onFormatPrice(thanks_fee));
		}

		// 显示消息数据
		setChatMessage();
		showAndHidThanksFee();

	}

	LatLng ll_start;
	View sn_view;
	public boolean isStatusChange = false;
	public int jishi_time = 100;
	public int drivercnt;

	/**
	 * 市内的地图样式
	 */
	public void setSnMap() {
		try {
			isNoSliding(true);
			// 起始点
			ll_start = new LatLng(list_order.get(viewId).getLocations()
					.getStart().getLocation().getLat(), list_order.get(viewId)
					.getLocations().getStart().getLocation().getLng());
			setMapStatus(ll_start, 17);

			OverlayOptions oo_start = new MarkerOptions().position(ll_start)
					.icon(bdSn).zIndex(9).draggable(false);
			if (mBaiduMap != null)
				mMarkerSn = (Marker) (mBaiduMap.addOverlay(oo_start));
			position_near.setLatLng(ll_start);
			LayoutInflater inflater = LayoutInflater.from(context);
			sn_view = (View) inflater.inflate(R.layout.map_sn, null);
			tv_notificati_car = (TextView) sn_view
					.findViewById(R.id.tv_notificati_car);
			mCircleProgressView = (CircleProgressView) sn_view
					.findViewById(R.id.mCircleProgressView);
			DecimalFormat df = new DecimalFormat("0.0");
			mCircleProgressView.setProgress(pressed,
					df.format(Double.parseDouble(pressed + "") / 100));
			setDrivercnt(drivercnt);
			if (ll_start != null) {
				mInfoWindowSN = new InfoWindow(sn_view, ll_start,
						-DensityUtil.dip2px(context, 30));
			}
			if (mBaiduMap != null) {
				mBaiduMap.showInfoWindow(mInfoWindowSN);
				showInfoWindow();
				mBaiduMap
						.setOnMapStatusChangeListener(new OnMapStatusChangeListener() {

							@Override
							public void onMapStatusChangeStart(MapStatus arg0) {
								isStatusChange = true;

							}

							@Override
							public void onMapStatusChangeFinish(MapStatus arg0) {
								isStatusChange = false;

							}

							@Override
							public void onMapStatusChange(MapStatus arg0) {
								// TODO Auto-generated method stub

							}
						});
				onLocationEnabled(false);
			}
			mHandler.postDelayed(position_near, 1000 * 5);
			RequestUtils.requesPushStatus(context, list_order.get(viewId)
					.getOrder_id(), list_order.get(viewId).getLine_id());
		} catch (Exception e) {
		}
	}

	public void showInfoWindow() {
		if (isStatusChange) {
			LayoutInflater inflater = LayoutInflater.from(context);
			sn_view = (View) inflater.inflate(R.layout.map_sn, null);
			tv_notificati_car = (TextView) sn_view
					.findViewById(R.id.tv_notificati_car);
			mCircleProgressView = (CircleProgressView) sn_view
					.findViewById(R.id.mCircleProgressView);
			DecimalFormat df = new DecimalFormat("0.0");
			mCircleProgressView.setProgress(pressed,
					df.format(Double.parseDouble(pressed + "") / 100));
			setDrivercnt(drivercnt);
			if (ll_start != null) {
				mInfoWindowSN = new InfoWindow(sn_view, ll_start,
						-DensityUtil.dip2px(context, 30));
			}
			if (mBaiduMap != null) {
				mBaiduMap.showInfoWindow(mInfoWindowSN);
			}
		}

		mHandler.postDelayed(position_time, 100);
	}

	/** 设置推送给司机数量 */
	public void setDrivercnt(int drivercnt) {
		if (tv_notificati_car != null)
			tv_notificati_car.setText(Html.fromHtml(String.format(
					context.getString(R.string.notificati_car),
					"<font color=\"#fe5000\">" + drivercnt + "</font>")));
	}

	/** 附近的司机 */
	public class MyPositionNearByDriver implements Runnable {
		private LatLng ll_start;

		public void setLatLng(LatLng ll_star) {
			this.ll_start = ll_star;
		}

		@Override
		public void run() {
			try {
				/** 获取附近的司机 */
				RequestUtils.requestNearByDriver(context, list_order
						.get(viewId).getOrder_id(), list_order.get(viewId)
						.getLine_id(), ll_start.longitude, ll_start.latitude,
						1000, true);
			} catch (Exception e) {
			}
		}

	}

	/** 计时 */
	public class MyPosition_Time implements Runnable {
		@Override
		public void run() {
			setProgress();
		}

	}

	public void setProgress() {
		if (mCircleProgressView != null) {
			pressed += 10;
			if (pressed == 3000)
				pressed = 0;
			DecimalFormat df = new DecimalFormat("0.0");
			mCircleProgressView.setProgress(pressed,
					df.format(Double.parseDouble(pressed + "") / 100));
			setDrivercnt(drivercnt);
			showInfoWindow();
		}
	}

	/**
	 * 设置聊天内容
	 */
	public void setChatMessage() {
		l_msg.clear();
		if (chatMessageListAdapter != null)
			chatMessageListAdapter.notifyDataSetChanged();
		if (map_jsmg.get(list_order.get(viewId).getOrder_id()) != null) {
			ArrayList<Map<String, String>> list_jsmg = map_jsmg.get(list_order
					.get(viewId).getOrder_id());
			for (int i = 0; i < list_jsmg.size(); i++) {
				JSONObject jmsg = null;
				JSONObject jmsg_data = null;
				Msgs.Data msgs_data = null;
				try {
					jmsg = new JSONObject(list_jsmg.get(i).get(
							DBcolumns.MESSAGE_JSON));
					jmsg_data = new JSONObject(jmsg.getString(GMsg.msg_data));
					msgs_data = (Msgs.Data) new JsonBuild().getData(
							Msgs.Data.class, jmsg_data.toString());
				} catch (Exception e) {
				}

				int message_type = Integer.parseInt(list_jsmg.get(i).get(
						DBcolumns.MESSAGE_TYPE));
				ChatMessage cm = new ChatMessage();
				switch (message_type) {
				case GMsg.ONLINE_PAIDAN:
					if (msgs_data != null) {
						cm.chatMsg = String.format(
								res.getString(R.string.order_paidan_msg),
								msgs_data.getDriver_name(),
								msgs_data.getCar_NO());
						cm.nickName = "nickName_I";
						cm.userID = YOU_ID;
						cm.time = list_jsmg.get(i).get(DBcolumns.MESSAGE_TIME);
						l_msg.add(cm);
					}
					break;
				case GMsg.ONLINE_ONCAR:
					if (msgs_data != null) {
						cm.chatMsg = String.format(
								res.getString(R.string.msg_oncar),
								msgs_data.getReason());
						cm.nickName = "nickName_I";
						cm.userID = YOU_ID;
						cm.time = list_jsmg.get(i).get(DBcolumns.MESSAGE_TIME);
						l_msg.add(cm);
					}
					break;
				case GMsg.ONLINE_CANCEL:
				case GMsg.ONLINE_KF_CANCEL:
					if (msgs_data != null) {
						cm.chatMsg = res.getString(R.string.order_cancel_msg);
						cm.nickName = "nickName_I";
						cm.userID = YOU_ID;
						cm.time = list_jsmg.get(i).get(DBcolumns.MESSAGE_TIME);
						l_msg.add(cm);
					}
					break;
				case GMsg.ONLINE_GAIPAI:
				case GMsg.ONLINE_KF_GAIPAIL:
				case GMsg.ONLINE_SJ_GAIPAIL:
					if (msgs_data != null) {
						cm.chatMsg = String.format(
								res.getString(R.string.order_gaipai_msg),
								msgs_data.getReason());
						cm.nickName = "nickName_I";
						cm.userID = YOU_ID;
						cm.time = list_jsmg.get(i).get(DBcolumns.MESSAGE_TIME);
						l_msg.add(cm);
					}
					break;
				case GMsg.ONLINE_RELOGIN:
					break;
				case GMsg.ONLINE_BUSY:
					if (msgs_data != null) {
						cm.chatMsg = msgs_data.getText();
						cm.nickName = "nickName_I";
						cm.userID = YOU_ID;
						cm.time = list_jsmg.get(i).get(DBcolumns.MESSAGE_TIME);
						l_msg.add(cm);
					}
					break;
				case GMsg.ONLINE_XIADAN:
				case GMsg.ONLINE_BG_ORDER:
					long appoint = DateFormat.onDate_Long(list_order
							.get(viewId).getAppoint_time());
					long time = DateFormat.getTime();
					long diff_time = appoint - time;
					if (diff_time < 1000 * 60 * estimat_time) {
						cm.chatMsg = res.getString(R.string.order_quickly_msg);
					} else {
						cm.chatMsg = res.getString(R.string.order_quickly_msg);
						// cm.chatMsg = String
						// .format(res
						// .getString(R.string.order_quickly2_msg),
						// DateFormat
						// .onCNTimeRemove_yyss(appoint - 1000 * 60 *
						// estimat_time));
					}

					cm.nickName = "nickName_I";
					cm.userID = YOU_ID;
					cm.time = list_jsmg.get(i).get(DBcolumns.MESSAGE_TIME);
					l_msg.add(cm);
					break;
				case ONLINE_CHAT:// 为自己发的,订单闲情
					int id = Integer.parseInt(list_jsmg.get(i).get(MSG_USER));
					sendMsgText(list_jsmg.get(i).get(MSG_CONTENT), id,
							list_jsmg.get(i).get(DBcolumns.MESSAGE_TIME));
				default:
					break;
				}
			}
			if (null == chatMessageListAdapter) {
				chatMessageListAdapter = new ChatMessageListAdapter(l_msg, this);
				mListView.setAdapter(chatMessageListAdapter);
			} else {
				chatMessageListAdapter.setL(l_msg);
				chatMessageListAdapter.notifyDataSetChanged();
			}
			mListView.setSelection(mListView.getBottom());
		}
	}

	/**
	 * 获取司机位置
	 */
	public void getDriverLocation(String driver_id) {
		if (driver_id == null || driver_id.equals("")) {
			return;
		}
		if (list_order.size() == 0)
			return;
		LogUtils.e("position", "开始获取地理位置" + driver_id);
		JSONObject jsonObject = null;
		try {
			jsonObject = new JSONObject();
			jsonObject.put("command", 4);
			jsonObject.put("line_id", list_order.get(viewId).getLine_id());
			jsonObject.put("uid", driver_id);

		} catch (JSONException e) {
			e.printStackTrace();
		}
		String sn_position_string = MyMesssage.sn_position + "_"
				+ (new Date().getTime());
		sn_position_list.add(sn_position_string);
		// 获取地理位置
		SDK.ins.mClient.request(mApplication.getUid(), sn_position_string, 30,
				jsonObject.toString());
		position_run.setDriver_Id(driver_id);
		mHandler.postDelayed(position_run, 1000 * 5);
	}

	/**
	 * 设置中心点位置
	 */
	public void setCenterPoint(double lat, double lng, final int zoom) {
		LatLng cenpt = new LatLng(lat, lng);
		setMapStatus(cenpt, zoom);

	}
	public void setMapStatus(LatLng ll) {
		setMapStatus(ll,-1);
	}
	/**
	 * 设置地图的位置
	 */
	public void setMapStatus(LatLng ll, final float zoom) {
		// 经纬度为空，则显示定位失败的位置
		if (ll.latitude == 0 || ll.longitude == 0) {
			ll = mApplication.ll_fail;
		}
		final LatLng mLatLng = ll;
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				MapStatus.Builder builder = new MapStatus.Builder();
				Point p = new Point(mapwidth_center, mapheight_center);
				builder.target(mLatLng).targetScreen(p);
				if(zoom>=0){
					builder.zoom(zoom);
				}
				final MapStatus mMapStatus = builder.build();
				MapStatusUpdate u = MapStatusUpdateFactory
						.newMapStatus(mMapStatus);
				// 改变地图状态
				if (mBaiduMap != null)
					try {
						mBaiduMap.animateMapStatus(u);
					} catch (Exception e) {
					}
			}
		}, 0);
	}

	/**
	 * 设置地图大小
	 */
	public void setMapZoom(final int zoom) {
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {
				MapStatusUpdate u = MapStatusUpdateFactory.zoomTo(zoom);
				if (mBaiduMap != null)
					try {
						mBaiduMap.animateMapStatus(u);
					} catch (Exception e) {
					}
			}
		}, 300);
	}

	/**
	 * 获取根据Id获取消息数据库
	 */
	public ArrayList<Map<String, String>> onRead_jsmg(String order_id) {
		ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
		db_jmsg = new JmsgDB();
		Cursor c = db_jmsg.onQuery(order_id);
		c.moveToFirst();
		if (c.getCount() > 0) {
			do {
				Map<String, String> map = new HashMap<String, String>();
				for (int i = 0; i < c.getColumnCount(); i++) {
					map.put(c.getColumnName(i), c.getString(i));
				}
				list.add(map);
			} while (c.moveToNext());
		}
		c.close();
		db_jmsg.onColse();
		return list;
	}

	@Override
	protected void onDestroy() {
		if (mInitTask != null
				&& mInitTask.getStatus() != AsyncTask.Status.FINISHED)
			mInitTask.cancel(true);
		removeHandler();
		mHandler.removeCallbacks(position_jifei);
		super.onDestroy();
	}

	protected void onPause() {
		super.onPause();
        //取消传感器
        mSensorManager.unregisterListener(this);
        //取消定位
        mApplication.onStopLocation();
	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == this.requestCode) {
			if (data != null) {
				int size = list_order.size();
				list_order.clear();
				list_order.addAll(db_myordering.onReadDB_ing(
						MyOrderActivity.num_ing, true));
				if (size != list_order.size()) {
					viewId = 0;
				}
				if (list_order.size() == 0)
					finish();
				else {
					initPage();
					onShowTitleStatus();
				}
			}
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

	@Override
	public void finish() {
		if (type_activity == 1) {
			Intent intent = new Intent();
			setResult(resultCode, intent);
		} else if (type_activity == 0) {
			Intent intent = new Intent();
			setResult(resultCode, intent);
		}
		super.finish();
	}

	@Override
	public void onNotify(int type, JSONObject jb, Msgs.Data msgs_data) {
		/** 是否继续执行父类 */
		boolean isContinue = true;
		String order_id = null;
		switch (type) {
		case GMsg.ONLINE_PAIDAN:
		case GMsg.ONLINE_GAIPAI:
		case GMsg.ONLINE_KF_GAIPAIL:
		case GMsg.ONLINE_SJ_GAIPAIL:
		case GMsg.ONLINE_ONCAR:
			order_id = msgs_data.getOrder_id();
			list_order.clear();
			list_order.addAll(db_myordering.onReadDB_ing(
					MyOrderActivity.num_ing, true));
			// 根据订单Id存储顺序id
			for (int i = 0; i < list_order.size(); i++) {
				map_id.put(list_order.get(i).getOrder_id(), i);
			}
			if (order_id != null) {
				try {
					// 不是市内抢单，能才变化viewId
					if (!isSnQiangdan())
						viewId = map_id.get(order_id);
				} catch (Exception e) {
					ToastUtil.showToast(context, R.string.order_change_refresh);
					finish();
				}

			}

			initPage();
			onShowTitleStatus();
			break;
		case GMsg.ONLINE_CANCEL:
		case GMsg.ONLINE_KF_CANCEL:
			if (mMySnTimeOutDialog != null) {
				mMySnTimeOutDialog.dismiss();
			}
			isContinue = false;
			try {
				JSONObject json_jmsg = jb.getJSONObject(GMsg.msg_jmsg);
				JSONObject json_data = new JSONObject(
						json_jmsg.getString(GMsg.msg_data));
				order_id = json_data.getString(GMsg.msg_order_id);
			} catch (JSONException e1) {
				// 出错了,该类型不是在线是离线
				try {
					JSONObject json_jmsg = jb.getJSONObject(GMsg.msg_jmsg);
					JSONArray msgs = json_jmsg.getJSONArray(GMsg.msg_msgs);
					if (msgs != null && msgs.length() >= 1) {
						JSONObject jo = new JSONObject(msgs.get(0).toString());
						JSONObject json_data = null;
						json_data = new JSONObject(jo.getString(GMsg.msg_data));
						order_id = json_data.getString(GMsg.msg_order_id);
					}
				} catch (Exception e) {
				}
			}
			if (order_id != null) {
				Intent intent = new Intent(context, OrderCancelReason.class);
				intent.putExtra(OrderMsg.extra_order_id, order_id);
				startActivityForResult(intent, requestCode);
			}
			break;
		case GMsg.ONLINE_OFFCAR:
			isContinue = false;
			try {
				JSONObject json_jmsg = jb.getJSONObject(GMsg.msg_jmsg);
				JSONObject json_data = new JSONObject(
						json_jmsg.getString(GMsg.msg_data));
				order_id = json_data.getString(GMsg.msg_order_id);
			} catch (JSONException e1) {
				// 出错了,该类型不是在线是离线
				try {
					JSONObject json_jmsg = jb.getJSONObject(GMsg.msg_jmsg);
					JSONArray msgs = json_jmsg.getJSONArray(GMsg.msg_msgs);
					if (msgs != null && msgs.length() >= 1) {
						JSONObject jo = new JSONObject(msgs.get(0).toString());
						JSONObject json_data = null;
						json_data = new JSONObject(jo.getString(GMsg.msg_data));
						order_id = json_data.getString(GMsg.msg_order_id);
					}
				} catch (Exception e) {
				}
			}
			if (order_id != null) {
				// 不是市内抢单，能才进入
				if (!isSnQiangdan()) {
					Intent intent = new Intent(context,
							OrderEvaluationActivity2.class);
					intent.putExtra(OrderMsg.order_id_finish, order_id);
					intent.putExtra(OrderMsg.finish_type, OrderMsg.finish_ing);
					startActivityForResult(intent, requestCode);
				}
			}
			break;
		case GMsg.ONLINE_POSITION:
			String sn_position = "";
			try {
				sn_position = jb.getString("sn");
			} catch (JSONException e1) {
			}
			if (sn_position_list.contains(sn_position))
				;
			LogUtils.e("position", "开始显示司机位置");
			try {
				String jsmg_string = jb.getString(GMsg.msg_jmsg);
				JSONObject jmsg_data = new JSONObject(jsmg_string);
				String position_string = jmsg_data.getString(GMsg.msg_position);
				Position position = (Position) new JsonBuild().getData(
						Position.class, position_string);
				// 经纬度等于0
				if (position.getLocation().getLat() == 0
						|| position.getLocation().getLng() == 0) {
					return;
				}
				LatLng llA = new LatLng(position.getLocation().getLat(),
						position.getLocation().getLng());
				// 已指派
				if (list_order.get(viewId).getOrder_status() == Value.ORDER_STATUS_ASSiIGN) {
					onDriverMarker(llA,true);
					setStartAndEndLevel(viewId);
				}
				// 已上车
				else if (list_order.get(viewId).getOrder_status() == Value.ORDER_STATUS_ONCAR) {// 隐藏标注
					onDriverMarker(llA,false);
					setCenterPoint(llA.latitude, llA.longitude, 17);
				}
			} catch (Exception e) {
			}
			break;
		case GMsg.ONLINE_DRIVERCN:
			// 司机数量
			if (isSnQiangdan() && msgs_data != null) {
				drivercnt = msgs_data.getDrivercnt();
			}
			break;
		case GMsg.ONLINE_SNTOQIANGDAN:
			try {
				if (list_near_marker != null) {
					for (int i = 0; i < list_near_marker.size(); i++) {
						if (list_near_marker.get(i) != null)
							list_near_marker.get(i).remove();
					}
				}
				list_near_marker.clear();
			} catch (Exception e) {
			}
			isContinue = false;
			initPage();
			break;
		case GMsg.ONLINE_KF_CHANGE:
		case GMsg.ONLINE_KF_CHANGE_ORDER:
		case GMsg.ONLINE_KF_CHANGE_PRICE:
		case GMsg.ONLINE_KF_CHANGE_PRICE2:
			isContinue = false;
			order_id = msgs_data.getOrder_id();
			if (!isSnQiangdan()) {
				viewId = map_id.get(order_id);
			} else {
				MessageDialog.onChangeDialog(context, type, msgs_data, false);
			}
			MyOrderingTask.getInstance(context).setOnOrderingFinishListener(
					this);
			MyOrderTask.getInstance(context);
			break;
		}
		if (isContinue) {
			super.onNotify(type, jb, msgs_data);
		}
	}

	@Override
	public void onNotify(int type, Object object) {
		/** 是否继续执行父类 */
		boolean isContinue = true;
		switch (type) {
		case GMsg.ONLINE_SNQIANGDAN:
			list_order.clear();
			if (db_myordering == null)
				db_myordering = new MyOrderingDB();
			list_order.addAll(db_myordering.onReadDB_ing(
					MyOrderActivity.num_ing, true));
			if (isSnQiangdan())
				isContinue = false;
			break;
		}
		if (isContinue) {
			super.onNotify(type, object);
		}
	}

	public class MyPosition_Run implements Runnable {
		private String driver_id;

		public void setDriver_Id(String driver_id) {
			this.driver_id = driver_id;
		}

		@Override
		public void run() {
			getDriverLocation(driver_id);
		}

	}

	/** 市内没15秒更新一次价格 */
	public class MyPosition_jiFei implements Runnable {

		@Override
		public void run() {
			MyOrderList mMyOrderList = list_order.get(viewId);
			int calc_type = mMyOrderList.getCalcType();
			if (calc_type == CarType.CALC_TYPE_jifei) {
				String order_id = mMyOrderList.getOrder_id();
				String line_id = mMyOrderList.getLine_id();
				RequestUtils.requesLastPriceInfo(context, order_id, line_id);
			}
		}

	}
	private View view_marker_driver;
	/**
	 * 显示司机覆盖物
	 */
    public void onDriverMarker(LatLng llA,boolean isShowDistance){
		// 司机覆盖物
		if (mMarkerA != null) {
			mMarkerA.remove();
		}
		TextView tv_content = null;
			LayoutInflater inflater = LayoutInflater.from(context);
			view_marker_driver = (View) inflater.inflate(
					R.layout.marker_siji, null);
		tv_content=(TextView)view_marker_driver.findViewById(R.id.tv_content);
		LatLng cenpt = new LatLng(mApplication.latitude,
				mApplication.longitude);
		if(isShowDistance) {

			int distance_about;
			double distance = DistanceUtil.getDistance(llA, cenpt) / 1000;
			if (distance >= 1) {
				distance_about = (int) Math.round(distance);
				tv_content.setText(Html
						.fromHtml("<font color=\"#169bdb\">"
								+ distance_about
								+ "</font><font color=\"#6a6d71\">"
								+ getString(R.string.text_km)
								+ "</font>"));
			} else {
				DecimalFormat df = new DecimalFormat("#.000");
				distance_about = Integer.parseInt(df.format(distance)
						.replace("0.", "").replace(".", ""));
				tv_content.setText(Html
						.fromHtml("<font color=\"#169bdb\">"
								+ distance_about
								+ "</font><font color=\"#6a6d71\">"
								+ getString(R.string.text_m)
								+ "</font>"));
			}
		}
		BitmapDescriptor bddriver  = BitmapDescriptorFactory
				.fromBitmap(ViewBitmap
						.getViewBitmap(view_marker_driver));
		OverlayOptions oo = new MarkerOptions()
				.position(llA)
				.icon(bddriver).zIndex(9)
				.draggable(false);
		if (mBaiduMap != null)
			mMarkerA = (Marker) (mBaiduMap
					.addOverlay(oo));
	}
	@Override
	public void startActivityForResult(Intent intent, int code) {
		removeHandler();
		super.startActivityForResult(intent, code);
	}

	public void onOrderingFinish(ArrayList<MyOrderList> list) {
		if (loaddialog != null) {
			loaddialog.dismiss();
		}
		int size = list_order.size();
		ArrayList<MyOrderList> list_myorder = new ArrayList<MyOrderList>();
		if (list != null) {
			// 过滤掉待支付
			for (int i = 0; i < list.size(); i++) {
				if (list.get(i).getOrder_status() < Value.ORDER_STATUS_OFFCAR) {
					list_myorder.add(list.get(i));
				}
			}
			if (size != list_myorder.size()) {
				viewId = 0;
			}
			if (list_myorder.size() == 0)
				finish();
			else {
				list_order.clear();
				list_order.addAll(list_myorder);
				initPage();
				onShowTitleStatus();
				initMap();
			}
		}
	}

	@Override
	public void onNotifyData(DATA_STATUS data_status, DATA_TYPE data_type,
			int status, Object object) {
		switch (data_type) {
		case ADDTHANKS:
			if (IsDataFail.isDataFail(data_status)) {
				return;
			}
			MyOrderingTask.getInstance(context).setOnOrderingFinishListener(
					this);
			MyOrderTask.getInstance(context);
			break;
		case CANCEL:
			if (IsDataFail.isDataFail(data_status)) {
				return;
			}
			// TODO Auto-generated method stub
			ToastUtil.showToast(context, R.string.cancel_success);
			db_myordering.onUpdate(list_order.get(viewId).getOrder_id(),
					Value.ORDER_STATUS_CANCEL);
			db_myorder.onUpdate(list_order.get(viewId).getOrder_id(),
					Value.ORDER_STATUS_CANCEL);
			Intent intent = new Intent(context, OrderCancelReason.class);
			intent.putExtra(OrderMsg.extra_order_id, list_order.get(viewId)
					.getOrder_id());
			startActivityForResult(intent, requestCode);
			break;
		case NEARBYDRIVERAR:
			try {
				if (IsDataFail.isDataFail(data_status)) {
					return;
				}
				NearByDriver mNearByDriver = (NearByDriver) object;
				ArrayList<DriverDetails> list = new ArrayList<NearByDriver.DriverDetails>();
				if (mNearByDriver != null)
					list = mNearByDriver.getList();
				try {
					if (list_near_marker != null) {
						for (int i = 0; i < list_near_marker.size(); i++) {
							if (list_near_marker.get(i) != null)
								list_near_marker.get(i).remove();
						}
					}
				} catch (Exception e) {
				}
				list_near_marker.clear();
				mHandler.postDelayed(position_near, 1000 * 5);
				if (list != null
						&& !list.isEmpty()
						&& list_order.get(viewId).getOrder_type() == Value.ORDER_TYPE_SN) {
					for (int i = 0; i < list.size(); i++) {
						Marker mMarker = null;
						LatLng ll = new LatLng(Double.parseDouble(list.get(i)
								.getLat()), Double.parseDouble(list.get(i)
								.getLng()));

						OverlayOptions oo = new MarkerOptions().position(ll)
								.icon(bdnear).zIndex(9).draggable(false);
						if (mBaiduMap != null)
							mMarker = (Marker) (mBaiduMap.addOverlay(oo));
						list_near_marker.add(mMarker);
					}
				} else {
					if (list_near_marker != null)
						list_near_marker.clear();
				}
			} catch (Exception e) {
			}
			break;
		case PUSHSTATUS:
			if (object != null) {
				PushStatus mPushStatus = (PushStatus) object;
				if (mPushStatus != null) {
					drivercnt = mPushStatus.getDrivercnt();
					setDrivercnt(drivercnt);
				}
			}
			break;
		case LASTPRICE:
			// 必须是服务中才能继续调用。
			if (isService(true, 0)) {
				mHandler.postDelayed(position_jifei, 15 * 1000);
			}
			if (object == null){
				return;
			}
			LastPriceInfo mLastPriceInfo = (LastPriceInfo) object;
			if (mLastPriceInfo == null && mLastPriceInfo.getInfo() == null)
				return;
			MyOrderList mMyOrderList = list_order.get(viewId);
			int calc_type = mMyOrderList.getCalcType();
			if (calc_type == CarType.CALC_TYPE_jifei) {
				setJifeiPrice( mLastPriceInfo.getInfo().total_price,true);
			}
			break;
		}
	}
	/**设置计费的价格
	 * isBaseDiscount是否打折
	 * */
    public void setJifeiPrice(double price,boolean isBaseDiscount){
    	MyOrderList mMyOrderList = list_order.get(viewId);
		int calc_type = mMyOrderList.getCalcType();
		if (calc_type == CarType.CALC_TYPE_jifei) {
		double base_discount=0;
		double thanks_fee=0;
		try{
			base_discount=Double.parseDouble(mMyOrderList.getPrice_Detail().getBaseDiscount());}catch(Exception e){
			base_discount=100;
		}
		try{
			thanks_fee=mMyOrderList.getPrice_Detail().getSchedule_fee();
		}catch(Exception e){}
		// 总费用
		double total_price=0;
		if(isBaseDiscount){
			 total_price =(price*((base_discount/100)))+thanks_fee;
		}else{
			 total_price =price;
		}
		// 优惠劵
		double coupon_sum = 0;
		//判断是下单立减还是优惠劵
		int sale_type=0;
		try{sale_type=list_order.get(viewId).getPrice_Detail().getSaleType();}catch(Exception e){}
		switch(sale_type){
		case UsableSale.sale_type_no:
			try {
				coupon_sum = list_order.get(viewId).getDiscount().getSum();
			} catch (Exception e) {
			}
			break;
		case UsableSale.sale_type_submit:
		case UsableSale.sale_type_online:
			try{coupon_sum=Double.parseDouble(FormatUtil.onFormatPrice(list_order.get(viewId).getPrice_Detail().getSaleAmount()));}catch(Exception e){}
			break;
		}
		tv_price.setText(String.format(
				getString((sale_type==UsableSale.sale_type_no)?R.string.service_price:R.string.service_price3),
				FormatUtil.onFormatPrice(total_price), FormatUtil.onFormatDecimal(coupon_sum)));
		double actual_price =Double.parseDouble(FormatUtil
				.onFormatPrice(total_price)) - coupon_sum;
		tv_total_price
				.setText(FormatUtil.onFormatDecimal(actual_price));
		}
    }
	public void setMapCenterHeight() {
		dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
		mapwidth_center = dm.widthPixels / 2;
		mapBoundsWidth=(dm.widthPixels);
		mapheight_center = dm.heightPixels;
		mapBoundsHeight=dm.heightPixels;

		int height_status = ScreenUtils.getStatusHeight(context);
		int height_title = MeasureViewUtils.getMeasuredHeight(title_comm);
		int height_top = MeasureViewUtils.getMeasuredHeight(layout_top);
		int height_ad = (layout_ad.getVisibility() == View.VISIBLE ? MeasureViewUtils
				.getMeasuredHeight(layout_ad) : 0);
		int topheight = height_status + height_title + height_top + height_ad;
		// 注意这边在加上头部的时候，，不能用topheight，因为地图是居于标题下面的，所以不能加，，然主界面，地图是居于状态栏下面的，所以可以加上标题的高度
		mapheight_center = (dm.heightPixels - topheight) / 2
				+ (height_top + height_ad);
		mapBoundsHeight=dm.heightPixels - topheight;
	}

	/** 设置出发地目的地的缩放比例尺 */
	public void setStartAndEndLevel(int ViewId) {
		// 不处理已上车
		if (list_order.get(viewId).getOrder_status() == Value.ORDER_STATUS_ONCAR) {
			return;
		}

		LatLng cenpt = new LatLng(mApplication.latitude, mApplication.longitude);
		int zoom = 0;
		double distance = 0;
		double tb_distance = 0;//上线距离
		double lr_distance = 0;//左右距离
		LatLng centll = null;
		if (isSnQiangdan()) {
			LatLng ll_start = new LatLng(list_order.get(ViewId).getLocations()
					.getStart().getLocation().getLat(), list_order.get(ViewId)
					.getLocations().getStart().getLocation().getLng());
			zoom = 17;
			setMapStatus(ll_start, zoom);
			return;
		}
		//新版本要替换成隐藏的，默认缩放比例到出发地
//		LatLng ll_start = new LatLng(list_order.get(ViewId).getLocations()
//				.getStart().getLocation().getLat(), list_order.get(ViewId)
//				.getLocations().getStart().getLocation().getLng());
//		zoom = 17;
//		setMapStatus(ll_start, zoom);
		else if (list_order.get(viewId).getOrder_status() == Value.ORDER_STATUS_ASSiIGN
				&& mMarkerA != null) {
			LatLng siji = new LatLng(mMarkerA.getPosition().latitude,
					mMarkerA.getPosition().longitude);
			centll = new LatLng((siji.latitude + cenpt.latitude) / 2,
					(siji.longitude + cenpt.longitude) / 2);
			ZoomUtils.setZoom(context,mBaiduMap,mapwidth_center,mapheight_center,mapBoundsWidth, mapBoundsHeight, siji, cenpt);
		} else {
			LatLng p1LL = new LatLng(list_order.get(ViewId).getLocations()
					.getStart().getLocation().getLat(), list_order.get(ViewId)
					.getLocations().getStart().getLocation().getLng());
			LatLng p2LL = new LatLng(list_order.get(ViewId).getLocations()
					.getEnd().getLocation().getLat(), list_order.get(ViewId)
					.getLocations().getEnd().getLocation().getLng());
			centll = new LatLng((p1LL.latitude + p2LL.latitude) / 2,
					(p1LL.longitude + p2LL.longitude) / 2);
			ZoomUtils.setZoom(context,mBaiduMap,mapwidth_center,mapheight_center, mapBoundsWidth, mapBoundsHeight, p1LL, p2LL);
		}
	}
	private View view_startprompt;
	private TextView startprompt_title;
	private TextView startprompt_content;
	/**
	 * 提示语，并且作为出发地的覆盖物显示
	 */
	public void onStartPrompt(){
		if (view_startprompt == null || view_startprompt == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			view_startprompt = (View) inflater.inflate(
					R.layout.marker_startprompt, null);
			startprompt_title = (TextView) view_startprompt
					.findViewById(R.id.tv_title);
			startprompt_content = (TextView) view_startprompt
					.findViewById(R.id.tv_content);
		}
	}
	@Override
	public void onShareDetaiFinish(ShareDetail mShareDetail) {
		if (mShareDetail != null) {
			int coupon_switch = mShareDetail.getState();
			if (coupon_switch == ShareDetail.STATUS_OPEN) {
				layout_ad.setVisibility(View.VISIBLE);
			} else {
				layout_ad.setVisibility(View.GONE);
			}
			new Handler().postDelayed(new Runnable() {

				@Override
				public void run() {
					setMapCenterHeight();
					iv_locate.performClick();
				}
			}, 500);
		}
	}

	@Override
	public void onLocationResult(BDLocation location) {
		onLocationEnabled();
		
	}

	@Override
	public void onLocationResult(ReverseGeoCodeResult result) {
		onLocationEnabled();
	}

	@Override
	public void onLocationFail(boolean isnet) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAccuracyChanged(Sensor arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}
	private float lastX;
	private float direction=0;
	@Override
	public void onSensorChanged(SensorEvent sensorEvent) {
		//方向感应检测
		 if(sensorEvent.sensor.getType()==Sensor.TYPE_ORIENTATION)  
	        {  
	            float x=sensorEvent.values[SensorManager.DATA_X];  
	            if(Math.abs(x-lastX)>1.0)  
	            {  
	             direction=x;
	             onLocationEnabled();
	            }  
	            lastX=x;  
	  
	        } 
	}
}
